-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Support subdirectory deployment and fix API path handling #311
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
base: main
Are you sure you want to change the base?
Conversation
|
@Biki-dev is attempting to deploy a commit to the dayuanjiang's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Hey, noticed #313 is working on the same feature. Would you two like to collaborate? @Biki-dev's utility approach + @zhangxin-github's about page coverage could make a more complete solution. |
DayuanJiang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution. I've added some inline comments—please take a look.
lib/base-path.ts
Outdated
| */ | ||
| export function getBasePath(): string { | ||
| // Only available on client side | ||
| if (typeof window === "undefined") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this check needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because window does not exist on the server, the check typeof window === "undefined" is there to prevent errors during SSR.If you want the function to function the same on both the server and the client, it can be remove also. The environment variable is available during build/SSR time.
app/manifest.ts
Outdated
| theme_color: "#171d26", | ||
| icons: [ | ||
| { | ||
| src: "/favicon-192x192.png", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The icon path alse need be updated with the basePath
@DayuanJiang sure |
Summary
This PR adds support for deploying the app under a subdirectory by introducing the
NEXT_PUBLIC_BASE_PATHconfiguration and updating client-side asset and API requests to respect the base path.Changes
basePathtonext.config.ts(readsNEXT_PUBLIC_BASE_PATH)lib/base-path.tswithgetApiEndpoint()andgetAssetUrl()getApiEndpoint()getAssetUrl()resolves #301