Witam,
Mam taki cel: Zrobić serwer www (http/https) w delphi za pomocą indy 10.
Powinien obsługiwać protokół http / https, poprawnie (klasy ala apatche) obsługiwać stronę www + obrazki + js (jquery) + css.
Niestety nie udało mi się znaleźć tutka, który by przedstawiał jak taki serwerek w delphi zrobić. W każdym coś nie działa albo nie ładują się obrazki albo css albo częściowo style się ładują a częściowo nie itp.
Na razie mam tyle kodu (nie wiele:/). Strona .htm się wyświetla i nic więcej nie działa.
Moje początkowe pytanie : Jak dodać poprawną obsługę do serwera http obrazków plików js css w tym czcionek itp. tak aby na przykład można było na nim uruchomić taki framework bootstrap ?
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, IdBaseComponent,
IdComponent, IdCustomTCPServer, IdCustomHTTPServer, IdHTTPServer, IdContext;
type
TForm1 = class(TForm)
IdHTTPServer1: TIdHTTPServer;
ButtonHTTPServerOn: TButton;
ButtonHTTPServerOff: TButton;
procedure ButtonHTTPServerOffClick(Sender: TObject);
procedure ButtonHTTPServerOnClick(Sender: TObject);
procedure IdHTTPServer1CommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ButtonHTTPServerOffClick(Sender: TObject);
begin
Form1.IdHTTPServer1.Active:=False;
end;
procedure TForm1.ButtonHTTPServerOnClick(Sender: TObject);
begin
Form1.IdHTTPServer1.DefaultPort:=80;
Form1.IdHTTPServer1.Active:=True;
end;
procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var Stream: TFileStream;
Groesse: String;
begin
if ARequestinfo.Document='/' then
begin
//AResponseinfo.ContentType:='text/html';
Stream:=TFileStream.Create('htdocs/index.htm', fmOpenRead or fmShareDenyWrite);
//AResponseInfo.ContentText :='<html><head><title>Error</title></head><body><h1>Access denied</h1></body></html>';
AResponseinfo.ContentStream:=Stream;
setlength(Groesse, Stream.Size);
Stream.Read(Groesse[1], Stream.Size);
end;
end;
end.