Home App Docs Blog Github

Conditional SSG and SSR on Next JS with Builder

Hello community, what I’m trying to achieve here is to make builder work within my next’s app that has ability to conditionally, depending on env variables, work as SSG or SSR. The way it works is that if user is on STAGING environment getServerSideProps is used to retrieve user information from server, ip in our case and it compares it to the ip whitelist, and if the ip match user is allowed to be redirected to the app, otherwise he is redirected somewhere else. When code is deployed to PRODUCTION, getServerSideProps function is deleted from the code with help of Babel and deployed, in this case our app is SSG now and doesn’t check for any ip and doesn’t do any redirections.
So the main issue is incompatibility of getServerSideProps and, functions that Builder uses, getStaticProps and getStaticPaths. They can’t be used simultaneously, so main idea is to make the nextjs app have some sort of index file that loads after _app and does all the magic with redirects based on env vars. In this case logically would be to move the pages that are loaded by Builder UI to a different location(folder) for example http://localhost:3000/content and edit them there but, this doesn’t work with dynamic routing components and page appear on the builder ui, but 404 displayed on local for the same page.
So to make long story short, how can I configure next js project with builder where the entry point for the pages to edit is located in the separate folder and not in the project route?

Guys, problem was solved by Nettlify team. Nettlify - Nextjs plugin This automatically takes away question of redirects from. After this setup nothing had to be changed from builder side. Maybe this will be useful for someone.