mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 15:55:54 +01:00
79 lines
2.4 KiB
ObjectPascal
79 lines
2.4 KiB
ObjectPascal
program articles_crud_server;
|
|
|
|
{$APPTYPE CONSOLE}
|
|
|
|
|
|
uses
|
|
System.SysUtils,
|
|
IdHTTPWebBrokerBridge,
|
|
MVCFramework,
|
|
MVCFramework.Commons,
|
|
MVCFramework.Signal,
|
|
MVCFramework.Logger,
|
|
MVCFramework.dotEnv,
|
|
Web.WebReq,
|
|
Web.WebBroker,
|
|
WebModuleUnit1 in 'WebModuleUnit1.pas' {WebModule1: TWebModule},
|
|
Controllers.Base in 'Controllers.Base.pas',
|
|
Controllers.Articles in 'Controllers.Articles.pas',
|
|
Services in 'Services.pas',
|
|
BusinessObjects in 'BusinessObjects.pas',
|
|
MainDM in 'MainDM.pas' {dmMain: TDataModule},
|
|
Commons in 'Commons.pas',
|
|
MVCFramework.ActiveRecord in '..\..\sources\MVCFramework.ActiveRecord.pas',
|
|
MVCFramework.Serializer.JsonDataObjects in '..\..\sources\MVCFramework.Serializer.JsonDataObjects.pas';
|
|
|
|
{$R *.res}
|
|
|
|
|
|
procedure RunServer(APort: Integer);
|
|
var
|
|
LServer: TIdHTTPWebBrokerBridge;
|
|
begin
|
|
LogI('** DMVCFramework Server ** build ' + DMVCFRAMEWORK_VERSION);
|
|
LogW('ARTICLES CRUD Sample. Use articles_crud_vcl_client.dproj to manage data');
|
|
LServer := TIdHTTPWebBrokerBridge.Create(nil);
|
|
try
|
|
LServer.OnParseAuthentication := TMVCParseAuthentication.OnParseAuthentication;
|
|
LServer.DefaultPort := APort;
|
|
LServer.KeepAlive := True;
|
|
LServer.MaxConnections := dotEnv.Env('dmvc.webbroker.max_connections', 0);
|
|
LServer.ListenQueue := dotEnv.Env('dmvc.indy.listen_queue', 500);
|
|
LServer.Active := True;
|
|
LogI('Listening on port ' + APort.ToString);
|
|
LogI('CTRL+C to shutdown the server');
|
|
WaitForTerminationSignal;
|
|
EnterInShutdownState;
|
|
LServer.Active := False;
|
|
finally
|
|
LServer.Free;
|
|
end;
|
|
end;
|
|
|
|
begin
|
|
ReportMemoryLeaksOnShutdown := True;
|
|
try
|
|
if WebRequestHandler <> nil then
|
|
WebRequestHandler.WebModuleClass := WebModuleClass;
|
|
|
|
dotEnvConfigure(
|
|
function: IMVCDotEnv
|
|
begin
|
|
Result := NewDotEnv
|
|
.UseStrategy(TMVCDotEnvPriority.FileThenEnv)
|
|
.UseLogger(procedure(LogItem: String)
|
|
begin
|
|
LogW('dotEnv: ' + LogItem);
|
|
end)
|
|
.Build(); //uses the executable folder to look for .env* files
|
|
end);
|
|
|
|
WebRequestHandlerProc.MaxConnections := dotEnv.Env('dmvc.handler.max_connections', 1024);
|
|
RunServer(dotEnv.Env('dmvc.server.port', 8080));
|
|
except
|
|
on E: Exception do
|
|
WriteLn(E.ClassName, ': ', E.Message);
|
|
end
|
|
|
|
end.
|