2023-09-25 23:55:28 +02:00
|
|
|
program htmx_mustache;
|
|
|
|
|
|
|
|
{$APPTYPE CONSOLE}
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.SysUtils,
|
|
|
|
MVCFramework,
|
|
|
|
MVCFramework.Signal,
|
|
|
|
MVCFramework.Logger,
|
2023-10-01 15:22:05 +02:00
|
|
|
MVCFramework.Console,
|
2023-09-25 23:55:28 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
Winapi.ShellAPI,
|
|
|
|
Winapi.Windows,
|
|
|
|
{$ENDIF }
|
|
|
|
IdHTTPWebBrokerBridge,
|
|
|
|
Web.WebReq,
|
|
|
|
Web.WebBroker,
|
|
|
|
WebModuleU in 'WebModuleU.pas' {WebModule1: TWebModule},
|
|
|
|
WebSiteControllerU in 'WebSiteControllerU.pas',
|
|
|
|
DAL in 'DAL.pas',
|
|
|
|
MyDataModuleU in '..\renders\MyDataModuleU.pas' {MyDataModule: TDataModule},
|
|
|
|
MVCFramework.HTMX in '..\htmx\MVCFramework.HTMX.pas', MVCFramework.Commons,
|
|
|
|
MVCFramework.DotEnv;
|
|
|
|
|
|
|
|
{$R *.res}
|
|
|
|
|
|
|
|
|
|
|
|
procedure RunServer(APort: Integer);
|
|
|
|
var
|
|
|
|
LServer: TIdHTTPWebBrokerBridge;
|
|
|
|
begin
|
|
|
|
ReportMemoryLeaksOnShutdown := True;
|
2023-10-01 15:22:05 +02:00
|
|
|
ResetConsole;
|
|
|
|
TextColor(TConsoleColor.Green);
|
2023-09-25 23:55:28 +02:00
|
|
|
Writeln(Format('Starting HTTP Server on port %d', [APort]));
|
2023-10-01 15:22:05 +02:00
|
|
|
ResetConsole;
|
2023-09-25 23:55:28 +02:00
|
|
|
LServer := TIdHTTPWebBrokerBridge.Create(nil);
|
|
|
|
try
|
|
|
|
LServer.DefaultPort := APort;
|
|
|
|
LServer.Active := True;
|
|
|
|
{$IFDEF MSWINDOWS}
|
2023-10-01 15:22:05 +02:00
|
|
|
//ShellExecute(0, 'open', 'http://localhost:8080', nil, nil, SW_SHOW);
|
2023-09-25 23:55:28 +02:00
|
|
|
{$ENDIF}
|
2023-10-01 15:22:05 +02:00
|
|
|
WriteLn('HTMX DMVCFramework Sample');
|
|
|
|
TextColor(TConsoleColor.Red);
|
|
|
|
Write('Ctrl+C to stop the server');
|
2023-09-25 23:55:28 +02:00
|
|
|
WaitForTerminationSignal;
|
|
|
|
EnterInShutdownState;
|
2023-10-01 15:22:05 +02:00
|
|
|
ResetConsole;
|
2023-09-25 23:55:28 +02:00
|
|
|
LServer.Active := False;
|
|
|
|
finally
|
|
|
|
LServer.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
begin
|
|
|
|
{ Enable ReportMemoryLeaksOnShutdown during debug }
|
|
|
|
// ReportMemoryLeaksOnShutdown := True;
|
|
|
|
IsMultiThread := True;
|
|
|
|
|
|
|
|
// DMVCFramework Specific Configuration
|
|
|
|
// When MVCSerializeNulls = True empty nullables and nil are serialized as json null.
|
|
|
|
// When MVCSerializeNulls = False empty nullables and nil are not serialized at all.
|
|
|
|
MVCSerializeNulls := True;
|
|
|
|
|
|
|
|
try
|
|
|
|
if WebRequestHandler <> nil then
|
|
|
|
WebRequestHandler.WebModuleClass := WebModuleClass;
|
|
|
|
|
|
|
|
dotEnvConfigure(
|
|
|
|
function: IMVCDotEnv
|
|
|
|
begin
|
|
|
|
Result := NewDotEnv
|
|
|
|
.WithStrategy(TMVCDotEnvPriority.FileThenEnv)
|
|
|
|
//if available, by default, loads default environment (.env)
|
|
|
|
.UseProfile('test') //if available loads the test environment (.env.test)
|
|
|
|
.UseProfile('prod') //if available loads the prod environment (.env.prod)
|
|
|
|
.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.
|