2013-10-29 16:51:16 +01:00
|
|
|
program BasicDemo;
|
|
|
|
|
|
|
|
{$APPTYPE CONSOLE}
|
|
|
|
|
2016-06-22 17:49:16 +02:00
|
|
|
|
2013-10-29 16:51:16 +01:00
|
|
|
uses
|
|
|
|
System.SysUtils,
|
|
|
|
Web.WebReq,
|
|
|
|
Web.WebBroker,
|
|
|
|
IdHTTPWebBrokerBridge,
|
2017-04-14 16:43:31 +02:00
|
|
|
MVCFramework.REPLCommandsHandlerU,
|
2013-10-29 16:51:16 +01:00
|
|
|
WebModuleUnit1 in 'WebModuleUnit1.pas' {WebModule1: TWebModule} ,
|
|
|
|
App1MainControllerU in 'App1MainControllerU.pas';
|
|
|
|
|
|
|
|
{$R *.res}
|
|
|
|
|
2016-06-22 17:49:16 +02:00
|
|
|
|
2013-10-29 16:51:16 +01:00
|
|
|
procedure RunServer(APort: Integer);
|
|
|
|
var
|
2017-04-14 16:43:31 +02:00
|
|
|
lServer: TIdHTTPWebBrokerBridge;
|
|
|
|
lCustomHandler: TMVCCustomREPLCommandsHandler;
|
|
|
|
lCmd, lStartupCommand: string;
|
2013-10-29 16:51:16 +01:00
|
|
|
begin
|
2017-04-14 16:43:31 +02:00
|
|
|
if ParamCount >= 1 then
|
|
|
|
lStartupCommand := ParamStr(1)
|
|
|
|
else
|
|
|
|
lStartupCommand := '';
|
|
|
|
|
|
|
|
lCustomHandler := function(const Value: String; const Server: TIdHTTPWebBrokerBridge; out Handled: Boolean): THandleCommandResult
|
|
|
|
begin
|
|
|
|
Handled := False;
|
|
|
|
Result := THandleCommandResult.Unknown;
|
|
|
|
|
|
|
|
// Write here your custom command for the REPL using the following form...
|
|
|
|
// ***
|
|
|
|
// Handled := False;
|
|
|
|
// if (Value = 'apiversion') then
|
|
|
|
// begin
|
|
|
|
// REPLEmit('Print my API version number');
|
|
|
|
// Result := THandleCommandResult.Continue;
|
|
|
|
// Handled := True;
|
|
|
|
// end
|
|
|
|
// else if (Value = 'datetime') then
|
|
|
|
// begin
|
|
|
|
// REPLEmit(DateTimeToStr(Now));
|
|
|
|
// Result := THandleCommandResult.Continue;
|
|
|
|
// Handled := True;
|
|
|
|
// end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
//Writeln(Format('Starting HTTP Server or port %d', [APort]));
|
2013-10-29 16:51:16 +01:00
|
|
|
LServer := TIdHTTPWebBrokerBridge.Create(nil);
|
|
|
|
try
|
|
|
|
LServer.DefaultPort := APort;
|
2017-04-14 16:43:31 +02:00
|
|
|
//LServer.Active := True;
|
|
|
|
//Writeln('Press RETURN to stop the server');
|
|
|
|
WriteLn('Write "quit" or "exit" to shutdown the server');
|
|
|
|
repeat
|
|
|
|
// TextColor(RED);
|
|
|
|
// TextColor(LightRed);
|
|
|
|
Write('-> ');
|
|
|
|
// TextColor(White);
|
|
|
|
if lStartupCommand.IsEmpty then
|
|
|
|
ReadLn(lCmd)
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
lCmd := lStartupCommand;
|
|
|
|
lStartupCommand := '';
|
|
|
|
WriteLn(lCmd);
|
|
|
|
end;
|
|
|
|
|
|
|
|
case HandleCommand(lCmd.ToLower, LServer, lCustomHandler) of
|
|
|
|
THandleCommandResult.Continue:
|
|
|
|
begin
|
|
|
|
Continue;
|
|
|
|
end;
|
|
|
|
THandleCommandResult.Break:
|
|
|
|
begin
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
THandleCommandResult.Unknown:
|
|
|
|
begin
|
|
|
|
REPLEmit('Unknown command: ' + lCmd);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
until false;
|
|
|
|
|
2013-10-29 16:51:16 +01:00
|
|
|
finally
|
|
|
|
LServer.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
begin
|
|
|
|
ReportMemoryLeaksOnShutdown := True;
|
|
|
|
try
|
|
|
|
if WebRequestHandler <> nil then
|
|
|
|
WebRequestHandler.WebModuleClass := WebModuleClass;
|
|
|
|
WebRequestHandlerProc.MaxConnections := 1024;
|
|
|
|
RunServer(3000);
|
|
|
|
except
|
|
|
|
on E: Exception do
|
|
|
|
Writeln(E.ClassName, ': ', E.Message);
|
2014-09-05 12:47:40 +02:00
|
|
|
end;
|
2013-10-29 16:51:16 +01:00
|
|
|
|
|
|
|
end.
|