简体   繁体   English

使用 Next.js 的条件 SSR

[英]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.我正在使用托管在 Netlify 上的 Next.js 构建一个网站,我想限制对临时环境的访问,并通过根据我的 ip 白名单检查用户 ip 来允许它在生产环境中使用。

To do that I need to use getServerSideProps where I get the IP from headers and compare it.为此,我需要使用getServerSideProps从头中获取 IP 并进行比较。 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.看起来getServerSideProps不能基于环境变量有条件地运行,所以我目前坚持使用它。

Maybe someone had experience with same problem or can advice alternative approaches?也许有人有同样问题的经验或可以建议替代方法?

The solution to this issue was found within next.js itself.这个问题的解决方案是在 next.js 中找到的。 They released the plugin for Nettlify a couple of days ago, and now they support next js redirects.几天前他们发布了 Nettlify 的插件,现在他们支持下一个 js 重定向。 Essential Next.js plugin v4 release notes 基本 Next.js 插件 v4 发行说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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