Hello,
I use embedded webserver based on fpweb unit an in the current stage I need routing of different requests. I tried to use Route Syntax described her
https://wiki.lazarus.freepascal.org/fpWeb_Tutorial, but no luck, its not working with embedded server, only with simple http server realization such as this:
HTTPRouter.RegisterRoute('*', @DoHello);
Application.Port := 9000;
Application.Initialize;
Application.Run;
This is my code that describe and starting my webserver
type
THTTPServerThread = class(TThread)
strict private
FServer: TFPHTTPServer;
FRequest: TFPHTTPConnectionRequest;
FResponse: TFPHTTPConnectionResponse;
procedure DoHandleRequest(Sender: TObject;
var ARequest: TFPHTTPConnectionRequest;
var AResponse: TFPHTTPConnectionResponse);
procedure ShowRequest;
protected
procedure Execute; override;
public
constructor Create(APort: Word);
destructor Destroy; override;
procedure StopServer;
end;
{ THTTPServerThread }
constructor THTTPServerThread.Create(APort: Word);
begin
inherited Create(True);
FServer := TFPHttpServer.Create(nil);
FServer.Port := APort;
FServer.OnRequest := @DoHandleRequest;
FreeOnTerminate := True;
end;
destructor THTTPServerThread.Destroy;
begin
FServer.Free;
inherited;
end;
procedure THTTPServerThread.Execute;
begin
FServer.Active := True;
end;
procedure THTTPServerThread.StopServer;
begin
FServer.Active := False;
end;
FThread := THTTPServerThread.Create(9080);
FThread.OnTerminate := @ThreadTerminated;
Please help, when should put HTTPRouter.RegisterRoute line for requests routing?
Thanks