mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-16 00:05:53 +01:00
73 lines
2.4 KiB
ObjectPascal
73 lines
2.4 KiB
ObjectPascal
unit WebModuleU;
|
|
|
|
interface
|
|
|
|
uses System.SysUtils,
|
|
System.Classes,
|
|
Web.HTTPApp,
|
|
MVCFramework, MVCFramework.DotEnv;
|
|
|
|
type
|
|
TMyWebModule = class(TWebModule)
|
|
procedure WebModuleCreate(Sender: TObject);
|
|
procedure WebModuleDestroy(Sender: TObject);
|
|
private
|
|
FMVC: TMVCEngine;
|
|
public
|
|
{ Public declarations }
|
|
end;
|
|
|
|
var
|
|
WebModuleClass: TComponentClass = TMyWebModule;
|
|
|
|
implementation
|
|
|
|
{$R *.dfm}
|
|
|
|
uses
|
|
MainControllerU,
|
|
System.IOUtils,
|
|
MVCFramework.Commons,
|
|
MVCFramework.Middleware.Compression,
|
|
MVCFramework.Middleware.StaticFiles;
|
|
|
|
|
|
procedure TMyWebModule.WebModuleCreate(Sender: TObject);
|
|
begin
|
|
FMVC := TMVCEngine.Create(Self,
|
|
procedure(Config: TMVCConfig)
|
|
begin
|
|
Config.dotEnv := dotEnv;
|
|
// session timeout (0 means session cookie)
|
|
Config[TMVCConfigKey.SessionTimeout] := Config.dotEnv.Env('dmvc.session_timeout', '0');
|
|
//default content-type
|
|
Config[TMVCConfigKey.DefaultContentType] := Config.dotEnv.Env('dmvc.default.content_type', TMVCConstants.DEFAULT_CONTENT_TYPE);
|
|
//default content charset
|
|
Config[TMVCConfigKey.DefaultContentCharset] := Config.dotEnv.Env('dmvc.default.content_charset', TMVCConstants.DEFAULT_CONTENT_CHARSET);
|
|
//unhandled actions are permitted?
|
|
Config[TMVCConfigKey.AllowUnhandledAction] := Config.dotEnv.Env('dmvc.allow_unhandled_actions', 'false');
|
|
//default view file extension
|
|
Config[TMVCConfigKey.DefaultViewFileExtension] := Config.dotEnv.Env('dmvc.default.view_file_extension', 'html');
|
|
//view path
|
|
Config[TMVCConfigKey.ViewPath] := Config.dotEnv.Env('dmvc.view_path', 'templates');
|
|
//Max Record Count for automatic Entities CRUD
|
|
Config[TMVCConfigKey.MaxEntitiesRecordCount] := Config.dotEnv.Env('dmvc.max_entities_record_count', IntToStr(TMVCConstants.MAX_RECORD_COUNT));
|
|
//Enable Server Signature in response
|
|
Config[TMVCConfigKey.ExposeServerSignature] := Config.dotEnv.Env('dmvc.expose_server_signature', 'false');
|
|
// Max request size in bytes
|
|
Config[TMVCConfigKey.MaxRequestSize] := Config.dotEnv.Env('dmvc.max_request_size', IntToStr(TMVCConstants.DEFAULT_MAX_REQUEST_SIZE));
|
|
end);
|
|
FMVC.AddController(TMyController);
|
|
// To enable compression (deflate, gzip) just add this middleware as the last one
|
|
FMVC.AddMiddleware(TMVCCompressionMiddleware.Create);
|
|
end;
|
|
|
|
procedure TMyWebModule.WebModuleDestroy(Sender: TObject);
|
|
begin
|
|
FMVC.Free;
|
|
end;
|
|
|
|
|
|
|
|
end.
|