-
Notifications
You must be signed in to change notification settings - Fork 276
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
[Nextjs] Allow empty string for getPublicUrl #1656
Conversation
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.
Looking good, see a couple comments
packages/create-sitecore-jss/src/templates/nextjs/scripts/generate-config.ts
Outdated
Show resolved
Hide resolved
…tlify env vars; adjust unit tests
…fig and in config fallback plugin
Co-authored-by: Adam Brauer <[email protected]>
…nv variable; adjust unit tests
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.
Bit of scope increase, but now that we have the publicUrl
available on the JSS config, I think we should switch over to use it exclusively in the app template (vs calling getPublicUrl()
everywhere).
Here are the locations:
https://github.com/search?q=repo%3ASitecore%2Fjss+getPublicUrl%28%29+path%3A%2F%5Epackages%5C%2Fcreate-sitecore-jss%5C%2Fsrc%5C%2Ftemplates%5C%2F%2F&type=code
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.
One minor language fix if you want to change those, otherwise looks great!
packages/create-sitecore-jss/src/templates/nextjs-styleguide-tracking/src/Navigation.tsx
Outdated
Show resolved
Hide resolved
@@ -58,7 +57,7 @@ const sitemapApi = async ( | |||
const lastSegment = parseUrl[parseUrl.length - 1]; | |||
|
|||
return `<sitemap> | |||
<loc>${getPublicUrl()}/${lastSegment}</loc> | |||
<loc>${config.publicUrl}/${lastSegment}</loc> |
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.
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.
@matkovskyi can you verify if using empty string breaks your functionality?
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.
@kendoce Yes, an empty string can't be used here
…l, which can be empty
@@ -50,14 +50,16 @@ const sitemapApi = async ( | |||
if (!sitemaps.length) { | |||
return res.redirect('/404'); | |||
} | |||
|
|||
|
|||
const reqtHost = req.headers.host; |
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.
Will this handle localhost?
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.
yep, tested
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.
Looks good, assuming localhost is handled (see 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.
👍
Description / Motivation
In production non editing environments, it is desirable to use relative URLs for static assets (e.g. _next/*, images, etc). For this we need to allow for the PUBLIC_URL environment variable to be set as empty string - comment the PUBLIC_URL in the default .env; adjust the logic in the getPublicUrl() function so that empty string is not treated as wrong and also takes precedence over vercel and netlify variables.
Connected with that this PR addresses a specific scenario where in editing environment a component makes a call to a nextjs app api route, which fails because we don't have access to PUBLIC_URL on the client side.
Testing Details
Types of changes