diff --git a/examples/with-now-env/.env.build b/examples/with-now-env/.env.build new file mode 100644 index 000000000000..870d0a6f282f --- /dev/null +++ b/examples/with-now-env/.env.build @@ -0,0 +1,3 @@ +# Development keys, for production we recommend Now Secrets +SECRET=dev-key +ANOTHER_SECRET=another-dev-key \ No newline at end of file diff --git a/examples/with-now-env/README.md b/examples/with-now-env/README.md index b2d3bc044e26..d2ca4b0b072e 100644 --- a/examples/with-now-env/README.md +++ b/examples/with-now-env/README.md @@ -21,21 +21,28 @@ curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 cd with-now-env ``` -Install it and run: +Install it with `npm` or `yarn`: ```bash npm install -npm run dev +# or +yarn +``` + +Start the development server with [now](https://zeit.co/now) ([download](https://zeit.co/download)): + +```bash +now dev ``` -Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) +Deploy it to the cloud with `now`: ```bash now ``` -keep in mind that in order to deploy the app to `now` the env [secrets](https://zeit.co/docs/getting-started/secrets) defined in `now.json` should be listed in your account +keep in mind that in order to deploy the app to `now` the env [secrets](https://zeit.co/docs/getting-started/secrets) defined in `now.json` should be listed in your account. ## The idea behind the example -This example shows the usage of [now-env](https://github.com/zeit/now-env), it allows to use secrets in development that will be replaced in production by the secrets defined with [now](https://zeit.co/docs/getting-started/secrets) +This example shows the usage of [Now Secrets](https://zeit.co/docs/v2/deployments/environment-variables-and-secrets/?query=secret#securing-environment-variables-using-secrets) and [now dev](https://zeit.co/docs/v2/development/basics), it shows how to add environment variables in development that can be replaced in production by the secrets defined with [Now](https://zeit.co/now). diff --git a/examples/with-now-env/next.config.js b/examples/with-now-env/next.config.js index 1b59436b01c2..fe8172e1bfab 100644 --- a/examples/with-now-env/next.config.js +++ b/examples/with-now-env/next.config.js @@ -1,21 +1,8 @@ -/** - * After the next require you can use process.env to get your secrets - */ -if (process.env.NODE_ENV !== 'production') { - require('now-env') -} - console.log({ SECRET: process.env.SECRET, - ANOTHER_SECRET: process.env.ANOTHER_SECRET, - SECRET_FAIL: process.env.SECRET_FAIL + ANOTHER_SECRET: process.env.ANOTHER_SECRET }) -/** - * If some of the envs are public, like a google maps key, but you still - * want to keep them secret from the repo, the following code will allow you - * to share some variables with the client, configured at compile time. - */ module.exports = { env: { SECRET: process.env.SECRET diff --git a/examples/with-now-env/now-secrets.json b/examples/with-now-env/now-secrets.json deleted file mode 100644 index 169f57182acb..000000000000 --- a/examples/with-now-env/now-secrets.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "@my-secret-key": "keep-it-secret", - "@my-other-secret-key": "keep-it-secret-too" -} diff --git a/examples/with-now-env/now.json b/examples/with-now-env/now.json index 872ff148d78c..f04eefdb3c06 100644 --- a/examples/with-now-env/now.json +++ b/examples/with-now-env/now.json @@ -1,7 +1,15 @@ { - "env": { - "SECRET": "@my-secret-key", - "ANOTHER_SECRET": "@my-other-secret-key", - "SECRET_FAIL": "@this-is-not-defined" + "version": 2, + "builds": [ + { + "src": "package.json", + "use": "@now/next" + } + ], + "build": { + "env": { + "SECRET": "@my-secret-key", + "ANOTHER_SECRET": "@my-other-secret-key" + } } } diff --git a/examples/with-now-env/package.json b/examples/with-now-env/package.json index d640cc14eaa0..1408083efd7c 100644 --- a/examples/with-now-env/package.json +++ b/examples/with-now-env/package.json @@ -1,17 +1,10 @@ { "name": "with-now-env", "version": "2.0.0", - "scripts": { - "dev": "next", - "build": "next build", - "start": "next start" - }, + "license": "ISC", "dependencies": { "next": "latest", "react": "^16.7.0", "react-dom": "^16.7.0" - }, - "devDependencies": { - "now-env": "^3.0.4" } } diff --git a/examples/with-now-env/pages/index.js b/examples/with-now-env/pages/index.js index 4c41e115dea8..8025ef1a0c3c 100644 --- a/examples/with-now-env/pages/index.js +++ b/examples/with-now-env/pages/index.js @@ -2,8 +2,8 @@ export default () => (

Hello World! Here's a secret shared with the client using Next env:{' '} - {process.env.SECRET}, the secret is shared at compile - time, which means every reference to the secret is replaced with its value + {process.env.SECRET}, the secret is shared at build time, + which means every reference to the secret is replaced with its value