2023-10-06 00:52:49 +02:00
|
|
|
program ServerSideViewsMustache;
|
2019-01-08 12:48:27 +01:00
|
|
|
|
|
|
|
{$APPTYPE CONSOLE}
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.SysUtils,
|
2022-08-19 10:20:13 +02:00
|
|
|
MVCFramework,
|
|
|
|
MVCFramework.Signal,
|
2019-01-08 12:48:27 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
Winapi.ShellAPI,
|
|
|
|
Winapi.Windows,
|
|
|
|
{$ENDIF }
|
|
|
|
IdHTTPWebBrokerBridge,
|
2023-10-06 12:30:40 +02:00
|
|
|
MVCFramework.View.Renderers.Mustache,
|
2019-01-08 12:48:27 +01:00
|
|
|
Web.WebReq,
|
|
|
|
Web.WebBroker,
|
|
|
|
WebModuleU in 'WebModuleU.pas' {WebModule1: TWebModule},
|
|
|
|
WebSiteControllerU in 'WebSiteControllerU.pas',
|
|
|
|
DAL in 'DAL.pas',
|
2023-10-06 00:52:49 +02:00
|
|
|
MyDataModuleU in '..\renders\MyDataModuleU.pas' {MyDataModule: TDataModule},
|
2023-10-06 12:30:40 +02:00
|
|
|
CustomMustacheHelpersU in 'CustomMustacheHelpersU.pas',
|
|
|
|
SynMustache,
|
|
|
|
MVCFramework.Serializer.URLEncoded in '..\..\sources\MVCFramework.Serializer.URLEncoded.pas';
|
2019-01-08 12:48:27 +01:00
|
|
|
|
|
|
|
{$R *.res}
|
|
|
|
|
|
|
|
|
|
|
|
procedure RunServer(APort: Integer);
|
|
|
|
var
|
|
|
|
LServer: TIdHTTPWebBrokerBridge;
|
|
|
|
begin
|
|
|
|
ReportMemoryLeaksOnShutdown := True;
|
|
|
|
Writeln(Format('Starting HTTP Server on port %d', [APort]));
|
|
|
|
LServer := TIdHTTPWebBrokerBridge.Create(nil);
|
|
|
|
try
|
|
|
|
LServer.DefaultPort := APort;
|
|
|
|
LServer.Active := True;
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
ShellExecute(0, 'open', 'http://localhost:8080', nil, nil, SW_SHOW);
|
|
|
|
{$ENDIF}
|
2022-08-19 10:20:13 +02:00
|
|
|
Write('Ctrl+C to stop the server');
|
|
|
|
WaitForTerminationSignal;
|
|
|
|
EnterInShutdownState;
|
|
|
|
LServer.Active := False;
|
2019-01-08 12:48:27 +01:00
|
|
|
finally
|
|
|
|
LServer.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
begin
|
|
|
|
ReportMemoryLeaksOnShutdown := True;
|
|
|
|
try
|
|
|
|
if WebRequestHandler <> nil then
|
|
|
|
WebRequestHandler.WebModuleClass := WebModuleClass;
|
2023-10-06 12:30:40 +02:00
|
|
|
|
|
|
|
// these helpers will be available to the mustache views as if they were the standard ones
|
|
|
|
TMVCMustacheHelpers.OnLoadCustomHelpers := procedure(var MustacheHelpers: TSynMustacheHelpers)
|
|
|
|
begin
|
|
|
|
TSynMustache.HelperAdd(MustacheHelpers, 'MyHelper1', TMyMustacheHelpers.MyHelper1);
|
|
|
|
TSynMustache.HelperAdd(MustacheHelpers, 'MyHelper2', TMyMustacheHelpers.MyHelper2);
|
|
|
|
end;
|
|
|
|
|
2019-01-08 12:48:27 +01:00
|
|
|
RunServer(8080);
|
|
|
|
except
|
|
|
|
on E: Exception do
|
|
|
|
Writeln(E.ClassName, ': ', E.Message);
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|