I wrote my first web application, but it does not work as expected.
I am attaching the minimal code below.
The 1st call, (like 'http://localhost:8080/contact') is server correctly and I see something like
it is 250811 19:54 oclock
at screen.
At the 2nd call, the browser hangs and a wheels rotates endlessly in the browser tag, suggesting that the browser is waiting for an answer (from the server) that never comes.
What is wrong in the code?
It seems that no condition like handled:=True is required in the router
method like it is when using a TFPWebModule...Thank you
DF
program webapp;
{$mode objfpc}{$H+}uses
classes,sysutils,
fphttpapp, httpdefs, httproute;procedure route_debug(ARequest: TRequest; AResponse: TResponse);
var
s:string;
begin
s:=FormatDatetime('yymmdd hh:nn',now);
AResponse.Code := 200;
AResponse.Content :=Format(
'<!DOCTYPE html>' +
'<html><head><title>Time</title></head>' +
'<body><h1>it is %s oclock</h1></body></html>',[s]);
AResponse.ContentType := 'text/html';
AResponse.ContentLength := Length(AResponse.Content);
AResponse.SendResponse;
end;
begin
HTTPRouter.registerRoute('*', @route_debug, false); // `false` = match
non strict
Application.port := 8080;
Application.threaded := true;
Application.initialize;
writeln('app listening on port ',Application.port); Application.run;end.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20250811/58d02bcd/attachment.htm>
