Skip to content

Commit

Permalink
added config options 'trace' (boolean) in config file. If enabled any…
Browse files Browse the repository at this point in the history
… request/response cycle is traced in the logs
  • Loading branch information
danieleteti committed Nov 10, 2021
1 parent 01dcade commit 9f29230
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 72 deletions.
10 changes: 8 additions & 2 deletions ConfigU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// MockJSONAPI
//
// Copyright (c) 2020 Daniele Teti
// Copyright (c) 2021 Daniele Teti
//
// https://github.com/danieleteti/mockjsonapi
//
Expand Down Expand Up @@ -30,7 +30,7 @@ interface
JsonDataObjects;

const
VERSION = '1.1.0';
VERSION = '1.1.2';

type
TConfig = class sealed
Expand All @@ -45,6 +45,7 @@ TConfig = class sealed
destructor Destroy; override;
function GetString(const ConfigName: string): string;
function GetInteger(const ConfigName: string): Integer;
function GetBoolean(const ConfigName: string): Boolean;
class destructor Destroy;
class property Instance: TConfig read GetConfig;
end;
Expand Down Expand Up @@ -78,6 +79,11 @@ destructor TConfig.Destroy;
sInstance.Free;
end;

function TConfig.GetBoolean(const ConfigName: string): Boolean;
begin
Result := fConfigDict.B[ConfigName];
end;

class function TConfig.GetConfig: TConfig;
begin
if not Assigned(sInstance) then
Expand Down
2 changes: 1 addition & 1 deletion EntitiesControllerU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// MockJSONAPI
//
// Copyright (c) 2020 Daniele Teti
// Copyright (c) 2021 Daniele Teti
//
// https://github.com/danieleteti/mockjsonapi
//
Expand Down
2 changes: 1 addition & 1 deletion WebModuleU.dfm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
object MainWM: TMainWM
OldCreateOrder = False
OnCreate = WebModuleCreate
OnDestroy = WebModuleDestroy
Actions = <>
Height = 230
Width = 415
PixelsPerInch = 96
end
12 changes: 10 additions & 2 deletions WebModuleU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ implementation

{$R *.dfm}

uses System.IOUtils, MVCFramework.Commons, MVCFramework.Middleware.CORS,
uses System.IOUtils,
MVCFramework.Commons,
MVCFramework.Middleware.CORS,
MVCFramework.Middleware.Trace,
SecurityHeadersMiddlewareU,
EntitiesControllerU,
SecurityHeadersMiddlewareU;
ConfigU;

procedure TMainWM.WebModuleCreate(Sender: TObject);
begin
Expand Down Expand Up @@ -78,6 +82,10 @@ procedure TMainWM.WebModuleCreate(Sender: TObject);
.AddController(TEntitiesController)
.AddMiddleware(TCORSMiddleware.Create)
.AddMiddleware(TSecurityHeadersMiddleware.Create);
if TConfig.Instance.GetBoolean('trace') then
begin
FMVC.AddMiddleware(TMVCTraceMiddleware.Create(4096))
end;
end;

procedure TMainWM.WebModuleDestroy(Sender: TObject);
Expand Down
3 changes: 2 additions & 1 deletion bin/config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"port": 8080
"port": 8080,
"trace": true
}
55 changes: 15 additions & 40 deletions bin/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,21 @@
"description": "NextGen"
}
],
"resource0661": [
{
"key": "changed",
"_oid": "DF0A1517-9A2B-46CB-BA1B-64A438C8C99D"
},
{
"key": "value01",
"_oid": "4218DC90-6E0C-4F15-9D84-EFEDA223232F"
},
{
"key": "value02",
"_oid": "F2CF3435-3358-4438-A625-3B5145968BB3"
},
{
"key": "value03",
"_oid": "C5774506-05F4-4625-836E-B0CF2C342F77"
},
{
"key": "value04",
"_oid": "93AB50ED-A110-421B-B4A2-5A9B651992E1"
},
{
"key": "value05",
"_oid": "878C8C3F-1053-4FB3-BC93-798E25159078"
},
{
"key": "value06",
"_oid": "CE5D82FD-52DB-4E0E-B447-6DECFF416757"
},
{
"key": "value07",
"_oid": "EDD51C4B-4E94-4B7D-BBDC-908DAA3FDF51"
},
{
"key": "value08",
"_oid": "8FA41951-E16B-408E-AE68-C9E5F6A309FE"
},
{
"key": "value09",
"_oid": "5BAC6E95-71B1-41A4-926E-2F653134A9FE"
"customers": [
{
"first_name": "Daniele",
"last_name": "Teti",
"contacts": [
{
"type": "phone",
"value": "333-333333"
},
{
"type": "email",
"value": "[email protected]"
}
],
"_oid": "34F37766-C037-40D5-B774-423BB1544BA2"
}
]
}
2 changes: 1 addition & 1 deletion buildlocal.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@echo off
rem @echo off
echo Building project...
call rsvars.bat
msbuild /t:build /p:config=Debug "mockjsonapi.dproj"
Expand Down
4 changes: 2 additions & 2 deletions mockjsonapi.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// MockJSONAPI
//
// Copyright (c) 2020 Daniele Teti
// Copyright (c) 2021 Daniele Teti
//
// https://github.com/danieleteti/mockjsonapi
//
Expand Down Expand Up @@ -93,7 +93,7 @@ begin
LServer.KeepAlive := True;
LServer.MaxConnections := 0;
LServer.ListenQueue := 200;

LogI('TRACE is ' + TConfig.Instance.GetBoolean('trace').ToString(TUseBoolStrs.True));
WriteLn('Write "quit" or "exit" to shutdown the server');
repeat
if lCmd.IsEmpty then
Expand Down
112 changes: 90 additions & 22 deletions mockjsonapi.dproj

Large diffs are not rendered by default.

0 comments on commit 9f29230

Please sign in to comment.