getStaticProps request context (host) when on Vercel #12848
-
My app uses the whole url, including subdomain and domain to request the correct data / styling data from the backend. When using Much like redsite.wiki.com/what-is-a-byte |
Beta Was this translation helpful? Give feedback.
Replies: 11 comments 62 replies
-
If you need to fetch data on the client-side for a static page, you might consider serving a static shell (loading state) and using SWR to fetch data. I'd need to hear more about what you're trying to build 😄 |
Beta Was this translation helpful? Give feedback.
-
I have a similar use case. Using the subdomain from host, would want to fetch some app constants. Use case is similar to how slack workspaces work. Different workspaces on different subdomains. |
Beta Was this translation helpful? Give feedback.
-
This is very old, is there any news on this? is there in the road map any idea to support this use case? |
Beta Was this translation helpful? Give feedback.
-
If you don't need both subdomain SSG and i18n at the same time, you can repurpose that system.
This is absolutely not intended use, and using this will prevent you from doing localization, but the concepts are the same - segment static pages based on a property derived from the host. |
Beta Was this translation helpful? Give feedback.
-
I think this discussion should be answered, as it seems like a next.js limitation: |
Beta Was this translation helpful? Give feedback.
-
I hope this solves the problem: https://multi-domain-first.vercel.app/ by leerob |
Beta Was this translation helpful? Give feedback.
-
@adriano-tirloni Here’s an example of hosting multiple domains on the same Next.js site (while maintaining multiple languages and static site generation/SSG), using Next.js’ i18n system: |
Beta Was this translation helpful? Give feedback.
-
You can use the host in rewrites in 10.2 https://nextjs.org/docs/api-reference/next.config.js/rewrites#header-cookie-and-query-matching so just send it through as a page param and build all pages under
Then its available in static props:
With fallbacks or blocking:
|
Beta Was this translation helpful? Give feedback.
-
As of Next 11, I'm currently using
next.config.js
Visiting If you're using |
Beta Was this translation helpful? Give feedback.
-
As of Next 12, this can now be accomplished in the edge handler |
Beta Was this translation helpful? Give feedback.
-
Quick update on this – we recently launched the Platforms Starter Kit that's a comprehensive template for building multi-tenant applications with built-in custom domains support (+ unlimited custom domains 😉): https://demo.vercel.pub/platforms-starter-kit Feel free to try it out and let us know what you think! :) |
Beta Was this translation helpful? Give feedback.
Quick update on this – we recently launched the Platforms Starter Kit that's a comprehensive template for building multi-tenant applications with built-in custom domains support (+ unlimited custom domains 😉): https://demo.vercel.pub/platforms-starter-kit
Feel free to try it out and let us know what you think! :)