mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-05-02 21:03:37 +02:00
51 lines
1.1 KiB
ObjectPascal
51 lines
1.1 KiB
ObjectPascal
program nodehttpdemo;
|
|
|
|
{$mode objfpc}
|
|
|
|
uses
|
|
nodejsapp, JS, Classes, SysUtils, nodeJS, node.http, node.net;
|
|
|
|
type
|
|
|
|
{ TMyApplication }
|
|
|
|
TMyApplication = class(TNodeJSApplication)
|
|
procedure doRun; override;
|
|
private
|
|
procedure doRequest(req: TNJSHTTPIncomingMessage; resp: TNJSHTTPServerResponse);
|
|
end;
|
|
|
|
procedure TMyApplication.doRequest(req : TNJSHTTPIncomingMessage; resp : TNJSHTTPServerResponse);
|
|
|
|
Var
|
|
S : string;
|
|
h : JSValue;
|
|
begin
|
|
resp.write('Hello World!'+sLineBreak);
|
|
resp.write('You asked for: '+req.URL+sLineBreak);
|
|
resp.write('You sent the following headers: '+sLineBreak);
|
|
for s in TJSObject.getOwnPropertyNames(req.headers) do
|
|
begin
|
|
H:=req.headers[S];
|
|
if jsTypeOf(H)='string' then
|
|
resp.Write('Header "'+S+'": '+String(H)+sLineBreak);
|
|
end;
|
|
resp.end_(); //end the response
|
|
end;
|
|
|
|
procedure TMyApplication.doRun;
|
|
|
|
begin
|
|
http.createServer(@DoRequest).listen(7770);
|
|
end;
|
|
|
|
var
|
|
Application : TMyApplication;
|
|
|
|
begin
|
|
Application:=TMyApplication.Create(nil);
|
|
Application.Initialize;
|
|
Application.Run;
|
|
Application.Free;
|
|
end.
|