mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-16 00:05:53 +01:00
88 lines
3.0 KiB
ObjectPascal
88 lines
3.0 KiB
ObjectPascal
|
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,
|
||
|
MVCFramework.View.Renderers.Mustache,
|
||
|
MVCFramework.Middleware.ActiveRecord,
|
||
|
MVCFramework.Middleware.StaticFiles,
|
||
|
MVCFramework.Middleware.Analytics,
|
||
|
MVCFramework.Middleware.Trace,
|
||
|
MVCFramework.Middleware.CORS,
|
||
|
MVCFramework.Middleware.ETag,
|
||
|
MVCFramework.Middleware.Compression, ControllerU;
|
||
|
|
||
|
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
|
||
|
FMVC.SetViewEngine(TMVCMustacheViewEngine);
|
||
|
// Server Side View - END
|
||
|
|
||
|
// Middleware
|
||
|
// Middleware - END
|
||
|
|
||
|
end;
|
||
|
|
||
|
procedure TMyWebModule.WebModuleDestroy(Sender: TObject);
|
||
|
begin
|
||
|
FMVC.Free;
|
||
|
end;
|
||
|
|
||
|
end.
|