Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
psycodad opened this issue May 19, 2022 · 5 comments
Open

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

psycodad opened this issue May 19, 2022 · 5 comments
Assignees
Labels
as-designed The behaviour is correct/expected

Comments

@psycodad
Copy link

psycodad commented May 19, 2022

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?

@fastbike
Copy link
Contributor

fastbike commented May 19, 2022

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
#217

@psycodad
Copy link
Author

psycodad commented May 19, 2022

  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.

@fastbike
Copy link
Contributor

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

@danieleteti
Copy link
Owner

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 danieleteti added the as-designed The behaviour is correct/expected label Jun 3, 2022
@psycodad
Copy link
Author

psycodad commented Jun 9, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
as-designed The behaviour is correct/expected
Projects
None yet
Development

No branches or pull requests

3 participants