2013-11-09 14:22:11 +01:00
|
|
|
program simplewebapplication;
|
|
|
|
{$APPTYPE CONSOLE}
|
|
|
|
|
2013-11-18 00:16:59 +01:00
|
|
|
|
2013-11-09 14:22:11 +01:00
|
|
|
uses
|
|
|
|
System.SysUtils,
|
|
|
|
Winapi.Windows,
|
2013-11-18 00:16:59 +01:00
|
|
|
Winapi.ShellAPI,
|
2013-11-09 14:22:11 +01:00
|
|
|
IdHTTPWebBrokerBridge,
|
|
|
|
Web.WebReq,
|
|
|
|
Web.WebBroker,
|
2013-11-18 00:16:59 +01:00
|
|
|
WebModuleU in 'WebModuleU.pas' {WebModule1: TWebModule} ,
|
2013-11-09 14:22:11 +01:00
|
|
|
SampleControllerU in 'SampleControllerU.pas';
|
|
|
|
|
|
|
|
{$R *.res}
|
|
|
|
|
2013-11-18 00:16:59 +01:00
|
|
|
|
2013-11-09 14:22:11 +01:00
|
|
|
procedure RunServer(APort: Integer);
|
|
|
|
var
|
|
|
|
LInputRecord: TInputRecord;
|
|
|
|
LEvent: DWord;
|
|
|
|
LHandle: THandle;
|
|
|
|
LServer: TIdHTTPWebBrokerBridge;
|
|
|
|
begin
|
|
|
|
Writeln(Format('Starting HTTP Server or port %d', [APort]));
|
|
|
|
LServer := TIdHTTPWebBrokerBridge.Create(nil);
|
|
|
|
try
|
|
|
|
LServer.DefaultPort := APort;
|
|
|
|
LServer.Active := True;
|
|
|
|
Writeln('Press ESC to stop the server');
|
2013-11-18 00:16:59 +01:00
|
|
|
ShellExecute(0, 'open', 'http://localhost:8080/index.elua', nil, nil, SW_SHOW);
|
2013-11-09 14:22:11 +01:00
|
|
|
LHandle := GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
while True do
|
|
|
|
begin
|
|
|
|
Win32Check(ReadConsoleInput(LHandle, LInputRecord, 1, LEvent));
|
|
|
|
if (LInputRecord.EventType = KEY_EVENT) and
|
2013-11-18 00:16:59 +01:00
|
|
|
LInputRecord.Event.KeyEvent.bKeyDown and
|
|
|
|
(LInputRecord.Event.KeyEvent.wVirtualKeyCode = VK_ESCAPE) then
|
2013-11-09 14:22:11 +01:00
|
|
|
break;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
LServer.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
begin
|
|
|
|
try
|
2013-11-18 00:16:59 +01:00
|
|
|
if WebRequestHandler <> nil then
|
|
|
|
WebRequestHandler.WebModuleClass := WebModuleClass;
|
2013-11-09 14:22:11 +01:00
|
|
|
RunServer(8080);
|
|
|
|
except
|
|
|
|
on E: Exception do
|
|
|
|
Writeln(E.ClassName, ': ', E.Message);
|
|
|
|
end
|
2013-11-18 00:16:59 +01:00
|
|
|
|
2013-11-09 14:22:11 +01:00
|
|
|
end.
|