Same codebase with ssg or ssr
Unanswered
Beveren posted this in #help-forum
BeverenOP
Hi, I would build an app that in production environment is built with ssg rendering and in stage or pre-production is built in ssr. The be server api is the same, and also the frontend(next.js) code is the same. I thought about using an ENV var that discriminates the production or stage environment, but what is the best approach or suggestion, for use the function getStaticProps and getServerSideProps in the same codebase? I can’t use ISR, because on production the deploy is going in a cdn, and in stage is deployed in a live server. Anyone that had the same problem? Thanks
4 Replies
good question, i doubt it's possible with the pages router. in the app router it might be possible, though.
BeverenOP
Hi, I use the app router version
app router doesn't have
getStaticProps or getServerSidePropsif you are using the app router, try
import { unstable_noStore as noStore } from "next/cache";
function Layout() {
if (process.env.NEXT_PUBLIC_ENVIRONMENT === "preproduction")
noStore();
// ...
}