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

[ADMIN] fix path concat to support admin serving at / path #17147

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

dekinderfiets
Copy link

What does it do?

Fixed the concatenation of paths.
When strapi.config.admin.path value is / (According to the docs, it should be supported), koa-static serving throws an AssertionError since the path is cannot be registered because the registered route is//:path* instead of /:path*.

Why is it needed?

It is needed so we can support serving the admin at https://example.com/ and not only at https://example.com/something

How to test it?

To reproduce the error, just set the url key at config/admin(.ts/.js) to / and start Strapi.

Related issue(s)/PR(s)

A few days ago someone faced the same issue at the forums:
https://forum.strapi.io/t/routing-for-separate-subdomains-for-api-and-admin-page/29177

@dekinderfiets dekinderfiets changed the title fix path concat to support admin serving at / path [ADMIN] fix path concat to support admin serving at / path Jun 29, 2023
@y2-shayb
Copy link

👌

@alexiuscrow
Copy link

This PR looks really great. I think this would greatly improve path routing.
Thanks, @dekinderfiets!

@vercel
Copy link

vercel bot commented Jul 4, 2023

Deployment failed with the following error:

The provided GitHub repository does not contain the requested branch or commit reference. Please ensure the repository is not empty.

@Marc-Roig Marc-Roig self-assigned this Jul 10, 2023
@gu-stav gu-stav removed their request for review July 11, 2023 07:20
@derrickmehaffy
Copy link
Member

I have a feeling this might break a few things in recent updates. @dekinderfiets have you tested this in a deployed environment with something like nginx and no-prefix base path? /

@dekinderfiets
Copy link
Author

dekinderfiets commented Aug 18, 2023

@derrickmehaffy

I have a feeling this might break a few things in recent updates. @dekinderfiets have you tested this in a deployed environment with something like nginx and no-prefix base path? /

I tried it all the variations mentioned above:

strapi.config.admin.path value result
"" "/:path*"
"/" "/:path*"
"/foo" "/foo/:path*"
"/foo/" "/foo/:path*"
"foo/" "/foo/:path*"
"foo" "/foo/:path*"

with an Nginx instance (Kubernetes Ingress) and it worked.
If you want a more stable and maintained solution for concatenating the url parts we can use url-join.
What do you think?

@derrickmehaffy
Copy link
Member

@derrickmehaffy

I have a feeling this might break a few things in recent updates. @dekinderfiets have you tested this in a deployed environment with something like nginx and no-prefix base path? /

I tried it all the variations mentioned above:

strapi.config.admin.path value result
"" "/:path*"
"/" "/:path*"
"/foo" "/foo/:path*"
"/foo/" "/foo/:path*"
"foo/" "/foo/:path*"
"foo" "/foo/:path*"
with an Nginx instance (Kubernetes Ingress) and it worked. If you want a more stable and maintained solution for concatenating the url parts we can use url-join. What do you think?

Ah I don't think we need that package, I was more so worried about the various nginx proxy (or generic proxy application) handling.

@dekinderfiets
Copy link
Author

dekinderfiets commented Aug 22, 2023

@derrickmehaffy Ok, so what else we need to merge this PR? 😃

@derrickmehaffy
Copy link
Member

Need to get engineers approval, I'll mention it to them in our internal slack

@derrickmehaffy
Copy link
Member

Experimental release in progress for testing: https://github.com/strapi/strapi/actions/runs/6224864249

@derrickmehaffy
Copy link
Member

Experimental version for testing: 0.0.0-experimental.e85c31c67a29c380cea20e131f8c2b8c4e4fbe82

@innerdvations
Copy link
Contributor

This looks good for me and seemed to work fine, but since it's part of the core path routing if someone else can do some more thorough QA to double-check me to make sure we don't break anything as a side effect ( @derrickmehaffy do you have time?) that would be great, then we can merge 🚀

@derrickmehaffy
Copy link
Member

Yeah I'll do some of my prod type testing with Nginx and caddy to see how well it works in a real world use-case.

Copy link

vercel bot commented May 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
contributor-docs ❌ Failed (Inspect) May 16, 2024 2:36pm

@dekinderfiets
Copy link
Author

Hi @derrickmehaffy, could you please let me know if you had a chance to check if the PR works in a real world use-case? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: fix This PR is fixing a bug source: core:admin Source is core/admin package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants