简体   繁体   中英

Conditional SSR with Next.js

I'm building a website with Next.js hosted on Netlify and I want to restrict access to the staging environment and allow it on production by checking users ips against my ip whitelist.

To do that I need to use getServerSideProps where I get the IP from headers and compare it. On staging, I don't need this functionality and the same pages should not have this funtionality. It looks like getServerSideProps can't be run conditionally based on env variables, so I'm currently stuck with it.

Maybe someone had experience with same problem or can advice alternative approaches?

The solution to this issue was found within next.js itself. They released the plugin for Nettlify a couple of days ago, and now they support next js redirects. Essential Next.js plugin v4 release notes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM