2018-09-25 15:36:53 +02:00
|
|
|
unit WebModuleU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.SysUtils,
|
|
|
|
System.Classes,
|
|
|
|
Web.HTTPApp,
|
2018-09-28 18:33:19 +02:00
|
|
|
MVCFramework,
|
|
|
|
FireDAC.Stan.Intf,
|
|
|
|
FireDAC.Stan.Option,
|
|
|
|
FireDAC.Stan.Error,
|
|
|
|
FireDAC.UI.Intf,
|
|
|
|
FireDAC.Phys.Intf,
|
|
|
|
FireDAC.Stan.Def,
|
|
|
|
FireDAC.Stan.Pool,
|
|
|
|
FireDAC.Stan.Async,
|
|
|
|
FireDAC.Phys,
|
|
|
|
FireDAC.Phys.MySQL,
|
|
|
|
FireDAC.Phys.MySQLDef,
|
|
|
|
FireDAC.VCLUI.Wait,
|
|
|
|
Data.DB,
|
2018-10-23 16:18:34 +02:00
|
|
|
FireDAC.Comp.Client,
|
|
|
|
FireDAC.Stan.Param,
|
|
|
|
FireDAC.DatS,
|
|
|
|
FireDAC.DApt.Intf,
|
|
|
|
FireDAC.DApt,
|
|
|
|
FireDAC.Comp.DataSet;
|
2018-09-25 15:36:53 +02:00
|
|
|
|
|
|
|
type
|
|
|
|
TMyWebModule = class(TWebModule)
|
2018-10-14 18:23:20 +02:00
|
|
|
FDQuery1: TFDQuery;
|
|
|
|
FDConnection1: TFDConnection;
|
2018-09-25 15:36:53 +02:00
|
|
|
procedure WebModuleCreate(Sender: TObject);
|
|
|
|
procedure WebModuleDestroy(Sender: TObject);
|
|
|
|
private
|
|
|
|
FMVC: TMVCEngine;
|
|
|
|
public
|
|
|
|
{ Public declarations }
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
WebModuleClass: TComponentClass = TMyWebModule;
|
2018-10-23 16:18:34 +02:00
|
|
|
ConnectionDefinitionName: string = '';
|
2018-09-25 15:36:53 +02:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
2020-10-22 19:42:18 +02:00
|
|
|
|
2018-09-25 15:36:53 +02:00
|
|
|
uses
|
|
|
|
System.IOUtils,
|
|
|
|
MVCFramework.Commons,
|
|
|
|
MVCFramework.ActiveRecordController,
|
|
|
|
MVCFramework.ActiveRecord,
|
2020-04-29 01:59:41 +02:00
|
|
|
MVCFramework.Middleware.StaticFiles,
|
|
|
|
FDConnectionConfigU,
|
|
|
|
OtherControllerU;
|
2018-09-25 15:36:53 +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] := '0';
|
|
|
|
// default content-type
|
2020-10-22 19:42:18 +02:00
|
|
|
Config[TMVCConfigKey.DefaultContentType] := TMVCConstants.DEFAULT_CONTENT_TYPE;
|
2018-09-25 15:36:53 +02:00
|
|
|
// default content charset
|
2020-10-22 19:42:18 +02:00
|
|
|
Config[TMVCConfigKey.DefaultContentCharset] := TMVCConstants.DEFAULT_CONTENT_CHARSET;
|
2018-09-25 15:36:53 +02:00
|
|
|
// unhandled actions are permitted?
|
|
|
|
Config[TMVCConfigKey.AllowUnhandledAction] := 'false';
|
|
|
|
// default view file extension
|
|
|
|
Config[TMVCConfigKey.DefaultViewFileExtension] := 'html';
|
|
|
|
// view path
|
|
|
|
Config[TMVCConfigKey.ViewPath] := 'templates';
|
|
|
|
// Enable Server Signature in response
|
|
|
|
Config[TMVCConfigKey.ExposeServerSignature] := 'true';
|
|
|
|
end);
|
2020-02-11 15:45:35 +01:00
|
|
|
|
|
|
|
FMVC.AddController(TOtherController, '/api/foo');
|
2018-09-25 15:36:53 +02:00
|
|
|
FMVC.AddController(TMVCActiveRecordController,
|
|
|
|
function: TMVCController
|
|
|
|
begin
|
2022-08-02 23:57:09 +02:00
|
|
|
Result := TMVCActiveRecordController.Create(ConnectionDefinitionName);
|
2018-09-25 15:36:53 +02:00
|
|
|
end, '/api/entities');
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMyWebModule.WebModuleDestroy(Sender: TObject);
|
|
|
|
begin
|
|
|
|
FMVC.Free;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|