You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since the npm package wasn't working for me, the following is from the guide to manually troubleshoot it. From what I understand, it should be checking for 'req' under the host variable in the absolute-url file, else do 'window.location.host' but not having much luck.
I'm new to React/Next.js so it's probably something simple I overlooked but would be appreciative if someone can look at this.
// PROJECT/lib/absolute-url.js
function absoluteUrl(req, setLocalhost) {
let protocol = 'https:'
let host = req
? req.headers['x-forwarded-host'] || req.headers['host']
: window.location.host
if (host.indexOf('localhost') > -1) {
if (setLocalhost) host = setLocalhost
protocol = 'http:'
}
return {
protocol: protocol,
host: host,
origin: protocol + '//' + host,
}
}
Next has updated its data fetch method and now getStaticProps doesn't return req anymore. getStaticProps is defined to be used for static generation only now. Alternative, you can use getServerSideProps to have access to req and then use absoluteUrl. See https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation for details.
I'm running into this error when I try to add this via npm as a package, as well as tried the guide on https://codeconqueror.com/blog/get-the-current-url-in-next-js listed in the README.
Since the npm package wasn't working for me, the following is from the guide to manually troubleshoot it. From what I understand, it should be checking for 'req' under the host variable in the absolute-url file, else do 'window.location.host' but not having much luck.
I'm new to React/Next.js so it's probably something simple I overlooked but would be appreciative if someone can look at this.
// PROJECT/lib/absolute-url.js
// PROJECT/components/layout.js
The text was updated successfully, but these errors were encountered: