Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2025-08

1st web application

7 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

duilio foschi

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>

Reply by email

Michael Van Canneyt
to duilio foschi

Hi,

I have tested your app, it works fine here.
I used FPC trunk on linux (I had to add cthreads since you use threads) ?

Michael.

duilio foschi wrote 57 lines
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.

Reply by email

duilio foschi
to Michael Van Canneyt

Oops. I forgot to add that I tested it only in windows...

Il Lun 11 Ago 2025, 20:14 Michael Van Canneyt via lazarus <

Show quoted text 76 lines
ha scritto: Hi, I have tested your app, it works fine here. I used FPC trunk on linux (I had to add cthreads since you use threads) ? Michael. On Mon, 11 Aug 2025, duilio foschi via lazarus wrote: > 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. > -- _______________________________________________ lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20250811/1d1958a2/attachment.htm>

Reply by email

duilio foschi
to duilio foschi

Any idea why the code does not word in Windows?

Il Lun 11 Ago 2025, 20:36 duilio foschi ha scritto:

Show quoted text 82 lines
Oops. I forgot to add that I tested it only in windows... Il Lun 11 Ago 2025, 20:14 Michael Van Canneyt via lazarus < > ha scritto: > > Hi, > > I have tested your app, it works fine here. > I used FPC trunk on linux (I had to add cthreads since you use threads) ? > > Michael. > > On Mon, 11 Aug 2025, duilio foschi via lazarus wrote: > > > 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. > > > -- > _______________________________________________ > lazarus mailing list > > https://lists.lazarus-ide.org/listinfo/lazarus >

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20250811/e49bda75/attachment-0001.htm>

Reply by email

Michael Van Canneyt
to duilio foschi
duilio foschi wrote
Any idea why the code does not word in Windows?

I see no reason why it would not work. Try disabling threading, see if that works ?

Michael.

Show quoted text 86 lines
Il Lun 11 Ago 2025, 20:36 duilio foschi ha scritto: > Oops. I forgot to add that I tested it only in windows... > > Il Lun 11 Ago 2025, 20:14 Michael Van Canneyt via lazarus < > > ha scritto: > >> >> Hi, >> >> I have tested your app, it works fine here. >> I used FPC trunk on linux (I had to add cthreads since you use threads) ? >> >> Michael. >> >> On Mon, 11 Aug 2025, duilio foschi via lazarus wrote: >> >>> 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. >>> >> -- >> _______________________________________________ >> lazarus mailing list >> >> https://lists.lazarus-ide.org/listinfo/lazarus >> >

Reply by email

duilio foschi
to Michael Van Canneyt

No joy :(

Il Lun 11 Ago 2025, 21:03 Michael Van Canneyt via lazarus <

Show quoted text 111 lines
ha scritto: On Mon, 11 Aug 2025, duilio foschi via lazarus wrote: > Any idea why the code does not word in Windows? I see no reason why it would not work. Try disabling threading, see if that works ? Michael. > > Il Lun 11 Ago 2025, 20:36 duilio foschi ha scritto: > >> Oops. I forgot to add that I tested it only in windows... >> >> Il Lun 11 Ago 2025, 20:14 Michael Van Canneyt via lazarus < >> > ha scritto: >> >>> >>> Hi, >>> >>> I have tested your app, it works fine here. >>> I used FPC trunk on linux (I had to add cthreads since you use threads) ? >>> >>> Michael. >>> >>> On Mon, 11 Aug 2025, duilio foschi via lazarus wrote: >>> >>>> 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. >>>> >>> -- >>> _______________________________________________ >>> lazarus mailing list >>> >>> https://lists.lazarus-ide.org/listinfo/lazarus >>> >> > -- _______________________________________________ lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20250811/177ffc96/attachment.htm>

Reply by email

Michael Van Canneyt
to duilio foschi

Firewall issue ? Version of FPC ? Stuck on exception in debugger ?

I have many servers in production with this, both on linux and windows. I see no reason why it would not work for you ?

Michael.

duilio foschi wrote 115 lines
No joy :( Il Lun 11 Ago 2025, 21:03 Michael Van Canneyt via lazarus < > ha scritto: > > > On Mon, 11 Aug 2025, duilio foschi via lazarus wrote: > >> Any idea why the code does not word in Windows? > > I see no reason why it would not work. Try disabling threading, see if that > works ? > > Michael. > > >> >> Il Lun 11 Ago 2025, 20:36 duilio foschi ha > scritto: >> >>> Oops. I forgot to add that I tested it only in windows... >>> >>> Il Lun 11 Ago 2025, 20:14 Michael Van Canneyt via lazarus < >>> > ha scritto: >>> >>>> >>>> Hi, >>>> >>>> I have tested your app, it works fine here. >>>> I used FPC trunk on linux (I had to add cthreads since you use > threads) ? >>>> >>>> Michael. >>>> >>>> On Mon, 11 Aug 2025, duilio foschi via lazarus wrote: >>>> >>>>> 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. >>>>> >>>> -- >>>> _______________________________________________ >>>> lazarus mailing list >>>> >>>> https://lists.lazarus-ide.org/listinfo/lazarus >>>> >>> >> > -- > _______________________________________________ > lazarus mailing list > > https://lists.lazarus-ide.org/listinfo/lazarus >

Reply by email