I have a Strapi backend on an environment (mine) and a NextJS frontend hosted on Vercel. My client has the same Strapi backend code on Google Cloud and the same frontend code hosted somewhere. I'm hosting preproduction environment, and my client hosts the production environment.
When I activate static generation on some pages in my NextJS app, and as my Strapi backend server is a small / slow one, I reach the limits of the RAM and my backend crashes. Also I want to keep Server Side Rendering for my preproduction environment because it is usefull when contributing content, as you can see your contribution instantly.
My client don't have any RAM limits, so I am trying to use NODE_ENV to make my NextJS application pages build in Static mode in the production environment, and in Server Side Rendering mode in my environment (preproduction).
But the point is NextJS don't allow me to do this:
if (process.env.NODE_ENV === 'production_static') {
export const getStaticProps = async (ctx) => {...};
} else {
export const getServerSideProps = async (ctx) => {...};
}
Because imports / export should be at the top level. I did research and tried to require one or another function using require(), and did lots of other tests but I don't have solutions, except editing the code each time I deliver a new version of the code to my client for a deploy to production environment...writing getStaticProps rather than getServerSideProps...witch is a waste of time.
Is there a solution to solve this problem using code (I mean deploying in Static on one env, and in SSR on another) ? Or should I consider upgrading my server (witch costs a lot) ?
Thank you !