mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 15:55:54 +01:00
100 lines
2.3 KiB
ObjectPascal
100 lines
2.3 KiB
ObjectPascal
program SwaggerPrimer;
|
|
|
|
{$APPTYPE CONSOLE}
|
|
|
|
uses
|
|
{$IFDEF MSWINDOWS}
|
|
WinAPI.ShellAPI,
|
|
WinAPI.Windows,
|
|
{$ENDIF}
|
|
System.SysUtils,
|
|
MVCFramework.Logger,
|
|
MVCFramework.Commons,
|
|
MVCFramework.REPLCommandsHandlerU,
|
|
Web.ReqMulti,
|
|
Web.WebReq,
|
|
Web.WebBroker,
|
|
IdContext,
|
|
IdHTTPWebBrokerBridge,
|
|
MyControllerU in 'MyControllerU.pas',
|
|
WebModuleU in 'WebModuleU.pas' {MyWebModule: TWebModule} ,
|
|
EntitiesU in 'EntitiesU.pas';
|
|
|
|
{$R *.res}
|
|
|
|
procedure RunServer(APort: Integer);
|
|
var
|
|
LServer: TIdHTTPWebBrokerBridge;
|
|
LCustomHandler: TMVCCustomREPLCommandsHandler;
|
|
LCmd: string;
|
|
begin
|
|
Writeln('** DMVCFramework Server ** build ' + DMVCFRAMEWORK_VERSION);
|
|
LCmd := 'start';
|
|
if ParamCount >= 1 then
|
|
LCmd := ParamStr(1);
|
|
|
|
LCustomHandler :=
|
|
function(const Value: String; const Server: TIdHTTPWebBrokerBridge; out Handled: Boolean)
|
|
: THandleCommandResult
|
|
begin
|
|
Handled := False;
|
|
Result := THandleCommandResult.Unknown;
|
|
end;
|
|
|
|
LServer := TIdHTTPWebBrokerBridge.Create(nil);
|
|
try
|
|
LServer.OnParseAuthentication := TMVCParseAuthentication.OnParseAuthentication;
|
|
LServer.DefaultPort := APort;
|
|
LServer.MaxConnections := 0;
|
|
LServer.ListenQueue := 200;
|
|
|
|
Writeln('Write "quit" or "exit" to shutdown the server');
|
|
repeat
|
|
if LCmd.IsEmpty then
|
|
begin
|
|
Write('-> ');
|
|
ReadLn(LCmd)
|
|
end;
|
|
try
|
|
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;
|
|
finally
|
|
LCmd := '';
|
|
end;
|
|
until False;
|
|
|
|
finally
|
|
LServer.Free;
|
|
end;
|
|
end;
|
|
|
|
begin
|
|
ReportMemoryLeaksOnShutdown := True;
|
|
IsMultiThread := True;
|
|
try
|
|
if WebRequestHandler <> nil then
|
|
WebRequestHandler.WebModuleClass := WebModuleClass;
|
|
WebRequestHandlerProc.MaxConnections := 1024;
|
|
{$IFDEF MSWINDOWS}
|
|
ShellExecute(0, PChar('open'), PChar('http://localhost:8080/swagger'), nil, nil, sw_show);
|
|
{$ENDIF}
|
|
RunServer(8080);
|
|
except
|
|
on E: Exception do
|
|
Writeln(E.ClassName, ': ', E.Message);
|
|
end;
|
|
|
|
end.
|