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
1924e3d8
Commit
1924e3d8
authored
Aug 30, 2018
by
Daniel Reinoso
Committed by
Tim Neutkens
Aug 30, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix with-custom-reverse-proxy example (#5064)
Fixes #5052. Example was using babel 6.
parent
4247a13f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
58 deletions
+51
-58
.babelrc
examples/with-custom-reverse-proxy/.babelrc
+1
-3
package.json
examples/with-custom-reverse-proxy/package.json
+0
-3
server.es6.js
examples/with-custom-reverse-proxy/server.es6.js
+0
-50
server.js
examples/with-custom-reverse-proxy/server.js
+50
-2
No files found.
examples/with-custom-reverse-proxy/.babelrc
View file @
1924e3d8
{
{
"presets": [
"presets": [
"next/babel",
"next/babel"
"latest",
"stage-0"
]
]
}
}
examples/with-custom-reverse-proxy/package.json
View file @
1924e3d8
...
@@ -8,9 +8,6 @@
...
@@ -8,9 +8,6 @@
"react-dom"
:
"16.2.0"
"react-dom"
:
"16.2.0"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"babel-preset-latest"
:
"^6.24.1"
,
"babel-preset-stage-0"
:
"^6.24.1"
,
"babel-register"
:
"^6.24.1"
,
"cross-env"
:
"^5.0.1"
,
"cross-env"
:
"^5.0.1"
,
"http-proxy-middleware"
:
"^0.17.4"
"http-proxy-middleware"
:
"^0.17.4"
},
},
...
...
examples/with-custom-reverse-proxy/server.es6.js
deleted
100644 → 0
View file @
4247a13f
/* eslint-disable no-console */
import
express
from
'express'
import
next
from
'next'
const
devProxy
=
{
'/api'
:
{
target
:
'https://swapi.co/api/'
,
pathRewrite
:
{
'^/api'
:
'/'
},
changeOrigin
:
true
}
}
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
env
=
process
.
env
.
NODE_ENV
const
dev
=
env
!==
'production'
const
app
=
next
({
dir
:
'.'
,
// base directory where everything is, could move to src later
dev
})
const
handle
=
app
.
getRequestHandler
()
let
server
app
.
prepare
()
.
then
(()
=>
{
server
=
express
()
// Set up the proxy.
if
(
dev
&&
devProxy
)
{
const
proxyMiddleware
=
require
(
'http-proxy-middleware'
)
Object
.
keys
(
devProxy
).
forEach
(
function
(
context
)
{
server
.
use
(
proxyMiddleware
(
context
,
devProxy
[
context
]))
})
}
// Default catch-all handler to allow Next.js to handle all other routes
server
.
all
(
'*'
,
(
req
,
res
)
=>
handle
(
req
,
res
))
server
.
listen
(
port
,
err
=>
{
if
(
err
)
{
throw
err
}
console
.
log
(
`> Ready on port
${
port
}
[
${
env
}
]`
)
})
})
.
catch
(
err
=>
{
console
.
log
(
'An error occurred, unable to start the server'
)
console
.
log
(
err
)
})
examples/with-custom-reverse-proxy/server.js
View file @
1924e3d8
require
(
'babel-register'
)
/* eslint-disable no-console */
module
.
exports
=
require
(
'./server.es6.js'
)
const
express
=
require
(
'express'
)
const
next
=
require
(
'next'
)
const
devProxy
=
{
'/api'
:
{
target
:
'https://swapi.co/api/'
,
pathRewrite
:
{
'^/api'
:
'/'
},
changeOrigin
:
true
}
}
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
env
=
process
.
env
.
NODE_ENV
const
dev
=
env
!==
'production'
const
app
=
next
({
dir
:
'.'
,
// base directory where everything is, could move to src later
dev
})
const
handle
=
app
.
getRequestHandler
()
let
server
app
.
prepare
()
.
then
(()
=>
{
server
=
express
()
// Set up the proxy.
if
(
dev
&&
devProxy
)
{
const
proxyMiddleware
=
require
(
'http-proxy-middleware'
)
Object
.
keys
(
devProxy
).
forEach
(
function
(
context
)
{
server
.
use
(
proxyMiddleware
(
context
,
devProxy
[
context
]))
})
}
// Default catch-all handler to allow Next.js to handle all other routes
server
.
all
(
'*'
,
(
req
,
res
)
=>
handle
(
req
,
res
))
server
.
listen
(
port
,
err
=>
{
if
(
err
)
{
throw
err
}
console
.
log
(
`> Ready on port
${
port
}
[
${
env
}
]`
)
})
})
.
catch
(
err
=>
{
console
.
log
(
'An error occurred, unable to start the server'
)
console
.
log
(
err
)
})
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