Now "NoRouteFound" error returns the correct content-type

This commit is contained in:
Daniele Teti 2024-02-21 14:41:25 +01:00
parent 49bbce0959
commit cc5789d56e
5 changed files with 19 additions and 9 deletions

View File

@ -34,6 +34,8 @@ type
function GetSum(const A, B: Integer): Integer;
[MVCPath('/sumsasfloat/($A)/($B)')]
function GetSumAsFloat(const A, B: Extended): Extended;
[MVCPath('/string/($A)/($B)')]
function GetConcatAsString(const A, B: String): String;
{ actions returning records }
[MVCPath('/records/single')]
@ -258,6 +260,11 @@ begin
Result := A + B;
end;
function TMyController.GetConcatAsString(const A, B: String): String;
begin
Result := A + B;
end;
function TMyController.GetWithCustomHeaders: TObjectList<TPerson>;
begin
Result := TObjectList<TPerson>.Create;

View File

@ -25,7 +25,7 @@ procedure RunServer(APort: Integer);
var
LServer: TIdHTTPWebBrokerBridge;
begin
Writeln('** DMVCFramework Server ** build ' + DMVCFRAMEWORK_VERSION);
LogI('** DMVCFramework Server ** build ' + DMVCFRAMEWORK_VERSION);
LServer := TIdHTTPWebBrokerBridge.Create(nil);
try
LServer.OnParseAuthentication := TMVCParseAuthentication.OnParseAuthentication;
@ -35,8 +35,8 @@ begin
LServer.ListenQueue := dotEnv.Env('dmvc.indy.listen_queue', 500);
LServer.Active := True;
WriteLn('Listening on port ', APort);
Write('CTRL+C to shutdown the server');
LogI('Listening on port ' + APort.ToString);
LogI('CTRL+C to shutdown the server');
WaitForTerminationSignal;
EnterInShutdownState;
LServer.Active := False;
@ -47,7 +47,7 @@ end;
begin
{ Enable ReportMemoryLeaksOnShutdown during debug }
// ReportMemoryLeaksOnShutdown := True;
ReportMemoryLeaksOnShutdown := True;
IsMultiThread := True;
// DMVCFramework Specific Configuration
@ -78,6 +78,6 @@ begin
RunServer(dotEnv.Env('dmvc.server.port', 8080));
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
LogE(E.ClassName + ': ' + E.Message);
end;
end.

View File

@ -44,7 +44,7 @@ uses
procedure TApp1MainController.HelloWorld;
begin
Render('Hello World called with GET');
if Context.Request.ThereIsRequestBody then
if Context.Request.HasBody then
Log('Body:' + Context.Request.Body);
end;

View File

@ -823,8 +823,8 @@ type
/// <summary>
/// Page calls GetRenderedView with sensible defaults.
/// Page method just concatenate -> commonheader_header_views + views + commonfooter_views
/// PageFragment ignore header and footer views
/// Page method with UseCommonHeadersAndFooters = True (default) concatenates
// commonheader_header_views + views + commonfooter_views
/// </summary>
function Page(const AViewNames: TArray<string>; const JSONModel: TJSONObject; const UseCommonHeadersAndFooters: Boolean = True): string; overload; inline;
@ -2788,6 +2788,7 @@ begin
begin
lContext.Response.StatusCode := http_status.NotFound;
lContext.Response.ReasonString := 'Not Found';
lContext.Response.SetContentStream(TStringStream.Create(), FConfigCache_DefaultContentType);
fOnRouterLog(lRouter, rlsRouteNotFound, lContext);
end
else

View File

@ -27,7 +27,8 @@ uses
Entities in '..\Several\Entities.pas',
EntitiesProcessors in '..\Several\EntitiesProcessors.pas',
MVCFramework.JSONRPC.Client in '..\..\..\sources\MVCFramework.JSONRPC.Client.pas',
MVCFramework.JSONRPC in '..\..\..\sources\MVCFramework.JSONRPC.pas';
MVCFramework.JSONRPC in '..\..\..\sources\MVCFramework.JSONRPC.pas',
MVCFramework.Serializer.Commons;
{$R *.res}
@ -80,6 +81,7 @@ end;
begin
ReportMemoryLeaksOnShutdown := True;
gLocalTimeStampAsUTC := False;
UseConsoleLogger := False;
try
if WebRequestHandler <> nil then