Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
7627eb87
Unverified
Commit
7627eb87
authored
Sep 05, 2018
by
Tim Neutkens
Committed by
GitHub
Sep 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use publicRuntimeConfig for universal-configuration-runtime example (#5101)
parent
777aab2b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
11 additions
and
32 deletions
+11
-32
README.md
examples/with-universal-configuration-runtime/README.md
+3
-1
env.js
examples/with-universal-configuration-runtime/lib/env.js
+0
-1
next.config.js
examples/with-universal-configuration-runtime/next.config.js
+5
-0
package.json
examples/with-universal-configuration-runtime/package.json
+0
-1
_document.js
...s/with-universal-configuration-runtime/pages/_document.js
+0
-27
index.js
examples/with-universal-configuration-runtime/pages/index.js
+3
-2
No files found.
examples/with-universal-configuration-runtime/README.md
View file @
7627eb87
...
@@ -41,4 +41,6 @@ now
...
@@ -41,4 +41,6 @@ now
## The idea behind the example
## The idea behind the example
This example show how to set custom environment variables for your application at runtime
This example show how to set custom environment variables for your application at runtime using the
`publicRuntimeConfig`
key in
`next.config.js`
For documentation see: https://github.com/zeit/next.js#exposing-configuration-to-the-server--client-side
examples/with-universal-configuration-runtime/lib/env.js
deleted
100644 → 0
View file @
777aab2b
export
default
(
typeof
window
!==
'undefined'
?
window
.
__ENV__
:
process
.
env
)
examples/with-universal-configuration-runtime/next.config.js
0 → 100644
View file @
7627eb87
module
.
exports
=
{
publicRuntimeConfig
:
{
API_URL
:
process
.
env
.
API_URL
}
}
examples/with-universal-configuration-runtime/package.json
View file @
7627eb87
...
@@ -5,7 +5,6 @@
...
@@ -5,7 +5,6 @@
"start"
:
"next start"
"start"
:
"next start"
},
},
"dependencies"
:
{
"dependencies"
:
{
"htmlescape"
:
"1.1.1"
,
"next"
:
"latest"
,
"next"
:
"latest"
,
"react"
:
"16.2.0"
,
"react"
:
"16.2.0"
,
"react-dom"
:
"16.2.0"
"react-dom"
:
"16.2.0"
...
...
examples/with-universal-configuration-runtime/pages/_document.js
deleted
100644 → 0
View file @
777aab2b
import
Document_
,
{
Head
,
Main
,
NextScript
}
from
'next/document'
import
htmlescape
from
'htmlescape'
const
{
API_URL
}
=
process
.
env
const
env
=
{
API_URL
}
export
default
class
Document
extends
Document_
{
static
async
getInitialProps
(
ctx
)
{
const
props
=
await
Document_
.
getInitialProps
(
ctx
)
return
props
}
render
()
{
return
(
<
html
>
<
Head
/>
<
body
>
<
Main
/>
<
script
dangerouslySetInnerHTML
=
{{
__html
:
'__ENV__ = '
+
htmlescape
(
env
)
}}
/
>
<
NextScript
/>
<
/body
>
<
/html
>
)
}
}
examples/with-universal-configuration-runtime/pages/index.js
View file @
7627eb87
import
React
from
'react'
import
React
from
'react'
import
env
from
'../lib/env
'
import
getConfig
from
'next/config
'
const
{
API_URL
}
=
env
const
{
publicRuntimeConfig
}
=
getConfig
()
const
{
API_URL
}
=
publicRuntimeConfig
export
default
class
extends
React
.
Component
{
export
default
class
extends
React
.
Component
{
static
async
getInitialProps
()
{
static
async
getInitialProps
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment