2024-07-02 23:06:30 +02:00
|
|
|
unit WebModuleU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.SysUtils,
|
|
|
|
System.Classes,
|
|
|
|
Web.HTTPApp,
|
|
|
|
MVCFramework;
|
|
|
|
|
|
|
|
type
|
|
|
|
TMyWebModule = class(TWebModule)
|
|
|
|
procedure WebModuleCreate(Sender: TObject);
|
|
|
|
procedure WebModuleDestroy(Sender: TObject);
|
|
|
|
private
|
|
|
|
fMVC: TMVCEngine;
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
WebModuleClass: TComponentClass = TMyWebModule;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.IOUtils,
|
|
|
|
MVCFramework.Commons,
|
2024-08-15 22:07:36 +02:00
|
|
|
MVCFramework.View.Renderers.TemplatePro,
|
2024-07-02 23:06:30 +02:00
|
|
|
MVCFramework.Middleware.ActiveRecord,
|
|
|
|
MVCFramework.Middleware.StaticFiles,
|
|
|
|
MVCFramework.Middleware.Analytics,
|
|
|
|
MVCFramework.Middleware.Trace,
|
|
|
|
MVCFramework.Middleware.CORS,
|
|
|
|
MVCFramework.Middleware.ETag,
|
2024-09-26 20:24:15 +02:00
|
|
|
MVCFramework.Middleware.Compression,
|
|
|
|
ControllerU;
|
2024-07-02 23:06:30 +02:00
|
|
|
|
|
|
|
procedure TMyWebModule.WebModuleCreate(Sender: TObject);
|
|
|
|
begin
|
|
|
|
FMVC := TMVCEngine.Create(Self,
|
|
|
|
procedure(Config: TMVCConfig)
|
|
|
|
begin
|
|
|
|
// session timeout (0 means session cookie)
|
|
|
|
Config[TMVCConfigKey.SessionTimeout] := dotEnv.Env('dmvc.session_timeout', '0');
|
|
|
|
//default content-type
|
|
|
|
Config[TMVCConfigKey.DefaultContentType] := dotEnv.Env('dmvc.default.content_type', TMVCMediaType.TEXT_HTML);
|
|
|
|
//default content charset
|
|
|
|
Config[TMVCConfigKey.DefaultContentCharset] := dotEnv.Env('dmvc.default.content_charset', TMVCConstants.DEFAULT_CONTENT_CHARSET);
|
|
|
|
//unhandled actions are permitted?
|
|
|
|
Config[TMVCConfigKey.AllowUnhandledAction] := dotEnv.Env('dmvc.allow_unhandled_actions', 'false');
|
|
|
|
//enables or not system controllers loading (available only from localhost requests)
|
|
|
|
Config[TMVCConfigKey.LoadSystemControllers] := dotEnv.Env('dmvc.load_system_controllers', 'true');
|
|
|
|
//default view file extension
|
|
|
|
Config[TMVCConfigKey.DefaultViewFileExtension] := dotEnv.Env('dmvc.default.view_file_extension', 'html');
|
|
|
|
//view path
|
|
|
|
Config[TMVCConfigKey.ViewPath] := dotEnv.Env('dmvc.view_path', 'templates');
|
|
|
|
//use cache for server side views (use "false" in debug and "true" in production for faster performances
|
|
|
|
Config[TMVCConfigKey.ViewCache] := dotEnv.Env('dmvc.view_cache', 'false');
|
|
|
|
//Max Record Count for automatic Entities CRUD
|
|
|
|
Config[TMVCConfigKey.MaxEntitiesRecordCount] := dotEnv.Env('dmvc.max_entities_record_count', IntToStr(TMVCConstants.MAX_RECORD_COUNT));
|
|
|
|
//Enable Server Signature in response
|
|
|
|
Config[TMVCConfigKey.ExposeServerSignature] := dotEnv.Env('dmvc.expose_server_signature', 'false');
|
|
|
|
//Enable X-Powered-By Header in response
|
|
|
|
Config[TMVCConfigKey.ExposeXPoweredBy] := dotEnv.Env('dmvc.expose_x_powered_by', 'true');
|
|
|
|
// Max request size in bytes
|
|
|
|
Config[TMVCConfigKey.MaxRequestSize] := dotEnv.Env('dmvc.max_request_size', IntToStr(TMVCConstants.DEFAULT_MAX_REQUEST_SIZE));
|
|
|
|
end);
|
|
|
|
|
|
|
|
// Controllers
|
|
|
|
FMVC.AddController(TMyController);
|
|
|
|
// Controllers - END
|
|
|
|
|
|
|
|
// Server Side View
|
2024-08-15 22:07:36 +02:00
|
|
|
FMVC.SetViewEngine(TMVCTemplateProViewEngine);
|
2024-07-02 23:06:30 +02:00
|
|
|
// Server Side View - END
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMyWebModule.WebModuleDestroy(Sender: TObject);
|
|
|
|
begin
|
|
|
|
FMVC.Free;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|