delphimvcframework icon indicating copy to clipboard operation
delphimvcframework copied to clipboard

Routing is broken when Config[TMVCConfigKey.PathPrefix] is set

Open psycodad opened this issue 3 years ago • 5 comments

If you set a Prefix like Config[TMVCConfigKey.PathPrefix] := '/v1/pjapi.dll'; then the function TMVCRouter.ExecuteRouting fails to find the correct route and ends always in a "404 Not Found" error. i had to change following code lines in MVCFramework.Router to get it work: replaced the line if not LRequestPathInfo.StartsWith(APathPrefix + LControllerMappedPath, True) then with if not LRequestPathInfo.StartsWith(LControllerMappedPath, True) then and if IsCompatiblePath(APathPrefix + LControllerMappedPath + LMethodPath, LRequestPathInfo, ARequestParams) then with if IsCompatiblePath(LControllerMappedPath + LMethodPath, LRequestPathInfo, ARequestParams) then"

I am not sure if i did it the right way, but it works now in isapi with prefix and local as exe without prefix. Maybe this is worth to get a deeper look on it?

psycodad avatar May 19 '22 07:05 psycodad

Why do you need that ugly path for ISAPI? My URLs look like

https://service.health.co.nz/v1/resource/2

I posted a guide here back in 2019 which explains how to host isapi files on IIS https://github.com/danieleteti/delphimvcframework/issues/217

fastbike avatar May 19 '22 10:05 fastbike

  1. I readed your guide some months ago, tried to implement step by step, but i was out of success. Maybe with a fresh installed IIS i would work, but in my case it did not.
  2. We have nearly 40 services running, many of them depends on each other by URL, all designed with the dll name in the URL. It is not easy to change this.
  3. If i can set a PathPrefix, it should work in any case.

psycodad avatar May 19 '22 10:05 psycodad

No probs, I understand that sometimes legacy deployment can rule out cleaner solutions 😀

fastbike avatar May 19 '22 23:05 fastbike

I am not sure if i did it the right way, but it works now in isapi with prefix and local as exe without prefix. Maybe this is worth to get a deeper look on it?

PathPrefix must be used only with ISAPI dll (at least if you don't want to prepend some prefix on all your routes dinamically). Please, try to use IFDEF and define PathPrefix for the isapi only for the ISAPI build.

Something like the following:

{$IF Not Defined(CONSOLE)}
Config[TMVCConfigKey.PathPrefix] := '/v1/pjapi.dll';
{$ELSE}  
Config[TMVCConfigKey.PathPrefix] := ''; // just to be clear
{$ENDIF}

danieleteti avatar Jun 03 '22 17:06 danieleteti

I am not sure if i did it the right way, but it works now in isapi with prefix and local as exe without prefix. Maybe this is worth to get a deeper look on it?

PathPrefix must be used only with ISAPI dll (at least if you don't want to prepend some prefix on all your routes dinamically). Please, try to use IFDEF and define PathPrefix for the isapi only for the ISAPI build.

Something like the following:

{$IF Not Defined(CONSOLE)}
Config[TMVCConfigKey.PathPrefix] := '/v1/pjapi.dll';
{$ELSE}  
Config[TMVCConfigKey.PathPrefix] := ''; // just to be clear
{$ENDIF}

That is exactly how i do it. The problem is that with ISAPI and the PathPrefix '/v1/pjapi.dll' it does not work. I would say it wont work with any PathPrefix you set other than '', when you do not make the changes i mentioned above. That is my point.

psycodad avatar Jun 09 '22 11:06 psycodad