Skip to content

Commit 7049c3b

Browse files
Luis Fernando Alvarez Dijjk
Luis Fernando Alvarez D
authored andcommitted
Updated with-now-env example (vercel#7694)
1 parent 39761e5 commit 7049c3b

File tree

7 files changed

+31
-37
lines changed

7 files changed

+31
-37
lines changed

examples/with-now-env/.env.build

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Development keys, for production we recommend Now Secrets
2+
SECRET=dev-key
3+
ANOTHER_SECRET=another-dev-key

examples/with-now-env/README.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,28 @@ curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2
2121
cd with-now-env
2222
```
2323

24-
Install it and run:
24+
Install it with `npm` or `yarn`:
2525

2626
```bash
2727
npm install
28-
npm run dev
28+
# or
29+
yarn
30+
```
31+
32+
Start the development server with [now](https://zeit.co/now) ([download](https://zeit.co/download)):
33+
34+
```bash
35+
now dev
2936
```
3037

31-
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
38+
Deploy it to the cloud with `now`:
3239

3340
```bash
3441
now
3542
```
3643

37-
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
44+
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.
3845

3946
## The idea behind the example
4047

41-
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)
48+
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).

examples/with-now-env/next.config.js

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
1-
/**
2-
* After the next require you can use process.env to get your secrets
3-
*/
4-
if (process.env.NODE_ENV !== 'production') {
5-
require('now-env')
6-
}
7-
81
console.log({
92
SECRET: process.env.SECRET,
10-
ANOTHER_SECRET: process.env.ANOTHER_SECRET,
11-
SECRET_FAIL: process.env.SECRET_FAIL
3+
ANOTHER_SECRET: process.env.ANOTHER_SECRET
124
})
135

14-
/**
15-
* If some of the envs are public, like a google maps key, but you still
16-
* want to keep them secret from the repo, the following code will allow you
17-
* to share some variables with the client, configured at compile time.
18-
*/
196
module.exports = {
207
env: {
218
SECRET: process.env.SECRET

examples/with-now-env/now-secrets.json

-4
This file was deleted.

examples/with-now-env/now.json

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
{
2-
"env": {
3-
"SECRET": "@my-secret-key",
4-
"ANOTHER_SECRET": "@my-other-secret-key",
5-
"SECRET_FAIL": "@this-is-not-defined"
2+
"version": 2,
3+
"builds": [
4+
{
5+
"src": "package.json",
6+
"use": "@now/next"
7+
}
8+
],
9+
"build": {
10+
"env": {
11+
"SECRET": "@my-secret-key",
12+
"ANOTHER_SECRET": "@my-other-secret-key"
13+
}
614
}
715
}

examples/with-now-env/package.json

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
{
22
"name": "with-now-env",
33
"version": "2.0.0",
4-
"scripts": {
5-
"dev": "next",
6-
"build": "next build",
7-
"start": "next start"
8-
},
4+
"license": "ISC",
95
"dependencies": {
106
"next": "latest",
117
"react": "^16.7.0",
128
"react-dom": "^16.7.0"
13-
},
14-
"devDependencies": {
15-
"now-env": "^3.0.4"
169
}
1710
}

examples/with-now-env/pages/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ export default () => (
22
<div className='hello'>
33
<p>
44
Hello World! Here's a secret shared with the client using Next env:{' '}
5-
<strong>{process.env.SECRET}</strong>, the secret is shared at compile
6-
time, which means every reference to the secret is replaced with its value
5+
<strong>{process.env.SECRET}</strong>, the secret is shared at build time,
6+
which means every reference to the secret is replaced with its value
77
</p>
88
<style jsx>{`
99
.hello {

0 commit comments

Comments
 (0)