LoginSignup
2
3

More than 3 years have passed since last update.

[nextjs 9] now.shでdotenvとかを使ってprocess.envを表示したい

Last updated at Posted at 2019-09-28

問題

Exposing configuration to the server / client side
で通常は問題ないが、nowをしてnow.shにデプロイするとprocess.envで設定した変数が見えなくなる。

解決方法

repo

now.jsonsecretsを使う。

next.config.js
require("dotenv").config()

module.exports = {
  env: {
    // これは `yarn dev` `yarn build && yarn start` `now`どこでも動く
    STATIC_ENV: "static value",
    // これは `now`すると見えなくなる
    FROM_DOT_ENV: process.env.FROM_DOT_ENV,
  },
}

now.jsonを追加して

now.json
{
  "build": {
    "env": {
      "FROM_DOT_ENV": "@from-dot-env"
    }
  }
}

Adding Secrets
now secrets add from-dot-env 'from now secret'
を走らせる。

[注意]
now secrets add FROM-DOT-ENV 'from now secret'
と大文字でやっても、小文字で保存される
now secrets ls
で確認出来る。

その後にnowをすると、now.shでもprocess.env.FROM_DOT_ENVが見える。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3