我在这里读到了关于serverRuntimeConfig
的文章:https://nextjs.org/docs/api-reference/next.config.js/runtime-configuration
现在我的next.config.js
是:
module.exports = withCSS({
target: 'serverless',
reactStrictMode: false,
env: {
SECRET: 'SECRET'
}
});
我在想,我应该用serverRuntimeConfig
代替env
作为我的秘密环境变量吗?优点/缺点是什么?
发布于 2020-10-09 12:22:49
Generally you'll want to use build-time environment variables to provide your configuration. The reason for this is that runtime configuration adds rendering / initialization overhead and is incompatible with Automatic Static Optimization.
# https://nextjs.org/docs/api-reference/next.config.js/runtime-configuration
正如他们所说的,next.config.js
中的运行时配置可能会导致开销。
因此,我建议在next.config.js
中使用env
,或者在这种新方法(https://nextjs.org/docs/basic-features/environment-variables)中使用.env*
文件。
使用您的秘密环境变量的代码应该在服务器端(API route、getStaticProps、getServerSideProps),而不是在客户端(组件...)。如果你在客户端引用它们,它们可能会暴露出来!
https://stackoverflow.com/questions/64261029
复制相似问题