delphimvcframework/samples/concurrency_speed_test/WebModuleU.pas

73 lines
2.4 KiB
ObjectPascal
Raw Normal View History

2019-05-19 14:06:12 +02:00
unit WebModuleU;
interface
uses System.SysUtils,
System.Classes,
Web.HTTPApp,
MVCFramework, MVCFramework.DotEnv;
2019-05-19 14:06:12 +02:00
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;
2019-05-19 14:06:12 +02:00
2019-05-19 14:06:12 +02:00
procedure TMyWebModule.WebModuleCreate(Sender: TObject);
begin
FMVC := TMVCEngine.Create(Self,
procedure(Config: TMVCConfig)
begin
Config.dotEnv := dotEnv;
2019-05-19 14:06:12 +02:00
// session timeout (0 means session cookie)
Config[TMVCConfigKey.SessionTimeout] := Config.dotEnv.Env('dmvc.session_timeout', '0');
2019-05-19 14:06:12 +02:00
//default content-type
Config[TMVCConfigKey.DefaultContentType] := Config.dotEnv.Env('dmvc.defaults.content_type', TMVCConstants.DEFAULT_CONTENT_TYPE);
2019-05-19 14:06:12 +02:00
//default content charset
Config[TMVCConfigKey.DefaultContentCharset] := Config.dotEnv.Env('dmvc.default.content_charset', TMVCConstants.DEFAULT_CONTENT_CHARSET);
2019-05-19 14:06:12 +02:00
//unhandled actions are permitted?
Config[TMVCConfigKey.AllowUnhandledAction] := Config.dotEnv.Env('dmvc.allow_unhandled_actions', 'false');
2019-05-19 14:06:12 +02:00
//default view file extension
Config[TMVCConfigKey.DefaultViewFileExtension] := Config.dotEnv.Env('dmvc.default.view_file_extension', 'html');
2019-05-19 14:06:12 +02:00
//view path
Config[TMVCConfigKey.ViewPath] := Config.dotEnv.Env('dmvc.view_path', 'templates');
2019-05-19 14:06:12 +02:00
//Max Record Count for automatic Entities CRUD
Config[TMVCConfigKey.MaxEntitiesRecordCount] := Config.dotEnv.Env('dmvc.max_entities_record_count', IntToStr(TMVCConstants.MAX_RECORD_COUNT));
2019-05-19 14:06:12 +02:00
//Enable Server Signature in response
Config[TMVCConfigKey.ExposeServerSignature] := Config.dotEnv.Env('dmvc.expose_server_signature', 'false');
2019-05-19 14:06:12 +02:00
// Max request size in bytes
Config[TMVCConfigKey.MaxRequestSize] := Config.dotEnv.Env('dmvc.max_request_size', IntToStr(TMVCConstants.DEFAULT_MAX_REQUEST_SIZE));
2019-05-19 14:06:12 +02:00
end);
FMVC.AddController(TMyController);
// To enable compression (deflate, gzip) just add this middleware as the last one
2019-05-19 14:06:12 +02:00
FMVC.AddMiddleware(TMVCCompressionMiddleware.Create);
end;
procedure TMyWebModule.WebModuleDestroy(Sender: TObject);
begin
FMVC.Free;
end;
2019-05-19 14:06:12 +02:00
end.