This is quite long time since the last posting to this topic, but now I got the answer and write here.
The web server application supports both old and new routing methods, without following line.
Application.LegacyRouting := true;
But I have to specify the web module name explicitly in the URL. For example,
http://mysite/test/cgi_test.exe/cgi-testWith legacyrouting true, I don't have to specify all of them if I only have one web module and action1 is defined as default action. Just following is fine.
http://mysite.com/test/cgi_test.exe (Of course, I do not add .exe in practice.)
And I can use both routing methods together. I add a simple example.
unit cgitest_u1;
{$mode objfpc}{$H+}
interface
uses
SysUtils, Classes, httpdefs, fpHTTP, fpWeb, httproute;
type
TFPWebModule1 = class(TFPWebModule)
procedure DataModuleRequest(Sender: TObject; ARequest: TRequest;
AResponse: TResponse; Var Handled: Boolean);
procedure HelloRequest(Sender: TObject; ARequest: TRequest;
AResponse: TResponse; var Handled: Boolean);
end;
var
FPWebModule1: TFPWebModule1;
implementation
{$R *.lfm}
procedure TFPWebModule1.DataModuleRequest(Sender: TObject; ARequest: TRequest;
AResponse: TResponse; Var Handled: Boolean);
begin
AResponse.Content := 'Response from web module';
// Handled := True;
end;
procedure TFPWebModule1.HelloRequest(Sender: TObject; ARequest: TRequest;
AResponse: TResponse; var Handled: Boolean);
begin
AResponse.Content := 'Hello, World';
Handled := True;
end;
procedure DoSomething(ARequest: TRequest; AResponse: TResponse);
begin
AResponse.Content := 'Response from DoSomething';
// Handled := True;
end;
initialization
// Httprouter.RegisterRoute('/', @Dosomething); --> if this is set, this is the default behavior.
RegisterHTTPModule('cgi-test', TFPWebModule1);
Httprouter.RegisterRoute('/do', @Dosomething);
end.