2017-03-01 21:40:57 +01:00
|
|
|
// ***************************************************************************
|
|
|
|
//
|
|
|
|
// Delphi MVC Framework
|
|
|
|
//
|
2020-01-06 16:49:18 +01:00
|
|
|
// Copyright (c) 2010-2020 Daniele Teti and the DMVCFramework Team
|
2017-03-01 21:40:57 +01:00
|
|
|
//
|
|
|
|
// https://github.com/danieleteti/delphimvcframework
|
|
|
|
//
|
|
|
|
// ***************************************************************************
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
// *************************************************************************** }
|
|
|
|
|
|
|
|
unit WebModuleUnit;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
2019-06-25 17:32:30 +02:00
|
|
|
uses
|
|
|
|
System.SysUtils,
|
2017-03-01 21:40:57 +01:00
|
|
|
System.Classes,
|
|
|
|
Web.HTTPApp,
|
2020-05-25 19:34:14 +02:00
|
|
|
MVCFramework,
|
2020-04-13 16:22:15 +02:00
|
|
|
FireDAC.Stan.StorageJSON
|
2020-05-25 19:34:14 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
,MVCFramework.Serializer.JsonDataObjects.OptionalCustomTypes
|
2019-07-07 17:25:11 +02:00
|
|
|
{$ENDIF}
|
|
|
|
;
|
2017-03-01 21:40:57 +01:00
|
|
|
|
|
|
|
type
|
2020-02-13 23:33:30 +01:00
|
|
|
TMainWebModule = class(TWebModule)
|
2020-04-13 16:22:15 +02:00
|
|
|
FDStanStorageJSONLink1: TFDStanStorageJSONLink;
|
2017-03-01 21:40:57 +01:00
|
|
|
procedure WebModuleCreate(Sender: TObject);
|
|
|
|
private
|
|
|
|
MVCEngine: TMVCEngine;
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
2020-02-13 23:33:30 +01:00
|
|
|
WebModuleClass: TComponentClass = TMainWebModule;
|
2017-03-01 21:40:57 +01:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
2019-06-25 17:32:30 +02:00
|
|
|
TestServerControllerU,
|
|
|
|
TestServerControllerExceptionU,
|
|
|
|
SpeedMiddlewareU,
|
|
|
|
MVCFramework.Middleware.Authentication,
|
|
|
|
System.Generics.Collections,
|
|
|
|
MVCFramework.Commons,
|
|
|
|
TestServerControllerPrivateU,
|
|
|
|
AuthHandlersU,
|
|
|
|
TestServerControllerJSONRPCU,
|
2020-05-25 19:34:14 +02:00
|
|
|
{$IFNDEF LINUX}
|
2020-04-13 16:22:15 +02:00
|
|
|
MVCFramework.View.Renderers.Mustache,
|
2020-05-25 19:34:14 +02:00
|
|
|
{$ENDIF}
|
2020-04-24 02:48:39 +02:00
|
|
|
MVCFramework.Middleware.Compression,
|
|
|
|
MVCFramework.Middleware.StaticFiles;
|
2017-03-01 21:40:57 +01:00
|
|
|
|
2020-02-13 23:33:30 +01:00
|
|
|
procedure TMainWebModule.WebModuleCreate(Sender: TObject);
|
2017-03-01 21:40:57 +01:00
|
|
|
begin
|
|
|
|
MVCEngine := TMVCEngine.Create(self,
|
|
|
|
procedure(Config: TMVCConfig)
|
|
|
|
begin
|
2017-05-18 00:02:22 +02:00
|
|
|
// no config here
|
2019-03-06 12:00:56 +01:00
|
|
|
Config[TMVCConfigKey.SessionTimeout] := '0'; // setting cookie
|
2019-05-02 17:38:57 +02:00
|
|
|
Config[TMVCConfigKey.PathPrefix] := '';
|
2020-04-21 17:04:04 +02:00
|
|
|
Config[TMVCConfigKey.ViewPath] := '..\templates';
|
2020-04-13 16:22:15 +02:00
|
|
|
Config[TMVCConfigKey.DefaultViewFileExtension] := 'html';
|
2017-03-01 21:40:57 +01:00
|
|
|
end, nil);
|
|
|
|
MVCEngine.AddController(TTestServerController)
|
|
|
|
.AddController(TTestPrivateServerController)
|
|
|
|
.AddController(TTestServerControllerExceptionAfterCreate)
|
|
|
|
.AddController(TTestServerControllerExceptionBeforeDestroy)
|
|
|
|
.AddController(TTestServerControllerActionFilters)
|
|
|
|
.AddController(TTestPrivateServerControllerCustomAuth)
|
2017-09-26 01:02:09 +02:00
|
|
|
.AddController(TTestJSONRPCController, '/jsonrpc')
|
2019-01-18 18:11:27 +01:00
|
|
|
.PublishObject(
|
|
|
|
function: TObject
|
|
|
|
begin
|
|
|
|
Result := TTestJSONRPCClass.Create
|
|
|
|
end, '/jsonrpcclass')
|
2020-08-05 09:50:06 +02:00
|
|
|
.PublishObject(
|
|
|
|
function: TObject
|
|
|
|
begin
|
|
|
|
Result := TTestJSONRPCHookClass.Create
|
|
|
|
end, '/jsonrpcclass1')
|
2019-01-18 18:11:27 +01:00
|
|
|
.AddController(TTestFaultController) // this will raise an exception
|
2018-08-08 17:11:45 +02:00
|
|
|
.AddController(TTestFault2Controller,
|
2019-01-18 18:11:27 +01:00
|
|
|
function: TMVCController
|
|
|
|
begin
|
|
|
|
Result := TTestFault2Controller.Create; // this will raise an exception
|
|
|
|
end)
|
2017-03-01 21:40:57 +01:00
|
|
|
.AddMiddleware(TMVCSpeedMiddleware.Create)
|
2020-05-27 11:28:22 +02:00
|
|
|
.AddMiddleware(TMVCStaticFilesMiddleware.Create('/', './www', 'index.html', False))
|
|
|
|
.AddMiddleware(TMVCStaticFilesMiddleware.Create('/static', './www', 'index.html', False))
|
|
|
|
.AddMiddleware(TMVCStaticFilesMiddleware.Create('/spa', './www', 'index.html', True))
|
2017-03-01 21:40:57 +01:00
|
|
|
.AddMiddleware(TMVCBasicAuthenticationMiddleware.Create(TBasicAuthHandler.Create))
|
2018-10-23 16:18:34 +02:00
|
|
|
.AddMiddleware(TMVCCustomAuthenticationMiddleware.Create(TCustomAuthHandler.Create, '/system/users/logged'))
|
|
|
|
.AddMiddleware(TMVCCompressionMiddleware.Create);
|
2019-07-07 17:25:11 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2020-05-25 19:34:14 +02:00
|
|
|
MVCEngine.SetViewEngine(TMVCMustacheViewEngine);
|
2019-07-07 17:25:11 +02:00
|
|
|
RegisterOptionalCustomTypesSerializers(MVCEngine.Serializers[TMVCMediaType.APPLICATION_JSON]);
|
|
|
|
{$ENDIF}
|
2017-03-01 21:40:57 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|