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
ba65b07d
Commit
ba65b07d
authored
Aug 10, 2017
by
Brikou CARRE
Committed by
Tim Neutkens
Aug 10, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ease running multiple examples at the same time with process.env.PORT (#2753)
parent
d0b95d9b
Show whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
64 additions
and
44 deletions
+64
-44
server.js
examples/custom-server-express/server.js
+3
-2
server.js
examples/custom-server-hapi/server.js
+3
-2
server.js
examples/custom-server-koa/server.js
+3
-2
server.js
examples/custom-server-micro/server.js
+3
-2
server.js
examples/custom-server/server.js
+3
-2
server.js
examples/page-transitions/server.js
+1
-1
server.js
examples/parameterized-routing/server.js
+3
-2
server.js
examples/root-static-files/server.js
+3
-2
server.js
examples/ssr-caching/server.js
+3
-2
server.js
examples/using-inferno/server.js
+3
-2
server.js
examples/using-preact/server.js
+3
-2
server.es6.js
examples/with-custom-reverse-proxy/server.es6.js
+1
-1
server.js
examples/with-firebase-authentication/server.js
+3
-2
server.js
examples/with-mobx/server.js
+3
-2
server.js
examples/with-next-routes/server.js
+3
-2
server.js
examples/with-pkg/server.js
+3
-2
server.js
examples/with-pretty-url-routing/server.js
+2
-2
server.js
examples/with-react-i18next/server.js
+3
-2
server.js
examples/with-react-intl/server.js
+3
-2
server.js
examples/with-socket.io/server.js
+3
-2
server.js
examples/with-static-export/server.js
+3
-2
server.js
examples/with-sw-precache/server.js
+3
-2
server.js
examples/with-url-object-routing/server.js
+3
-2
No files found.
examples/custom-server-express/server.js
View file @
ba65b07d
const
express
=
require
(
'express'
)
const
express
=
require
(
'express'
)
const
next
=
require
(
'next'
)
const
next
=
require
(
'next'
)
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
app
=
next
({
dev
})
const
app
=
next
({
dev
})
const
handle
=
app
.
getRequestHandler
()
const
handle
=
app
.
getRequestHandler
()
...
@@ -21,8 +22,8 @@ app.prepare()
...
@@ -21,8 +22,8 @@ app.prepare()
return
handle
(
req
,
res
)
return
handle
(
req
,
res
)
})
})
server
.
listen
(
3000
,
(
err
)
=>
{
server
.
listen
(
port
,
(
err
)
=>
{
if
(
err
)
throw
err
if
(
err
)
throw
err
console
.
log
(
'> Ready on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
examples/custom-server-hapi/server.js
View file @
ba65b07d
...
@@ -3,6 +3,7 @@ const Hapi = require('hapi')
...
@@ -3,6 +3,7 @@ const Hapi = require('hapi')
const
Good
=
require
(
'good'
)
const
Good
=
require
(
'good'
)
const
{
pathWrapper
,
defaultHandlerWrapper
}
=
require
(
'./next-wrapper'
)
const
{
pathWrapper
,
defaultHandlerWrapper
}
=
require
(
'./next-wrapper'
)
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
app
=
next
({
dev
})
const
app
=
next
({
dev
})
const
server
=
new
Hapi
.
Server
()
const
server
=
new
Hapi
.
Server
()
...
@@ -23,7 +24,7 @@ const pluginOptions = [
...
@@ -23,7 +24,7 @@ const pluginOptions = [
app
.
prepare
()
app
.
prepare
()
.
then
(()
=>
{
.
then
(()
=>
{
server
.
connection
({
port
:
3000
})
server
.
connection
({
port
})
server
.
register
(
pluginOptions
)
server
.
register
(
pluginOptions
)
.
then
(()
=>
{
.
then
(()
=>
{
server
.
route
({
server
.
route
({
...
@@ -48,7 +49,7 @@ app.prepare()
...
@@ -48,7 +49,7 @@ app.prepare()
console
.
log
(
'Error starting server'
)
console
.
log
(
'Error starting server'
)
console
.
log
(
error
)
console
.
log
(
error
)
}).
then
(()
=>
{
}).
then
(()
=>
{
console
.
log
(
'> Ready on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
})
})
examples/custom-server-koa/server.js
View file @
ba65b07d
...
@@ -2,6 +2,7 @@ const Koa = require('koa')
...
@@ -2,6 +2,7 @@ const Koa = require('koa')
const
next
=
require
(
'next'
)
const
next
=
require
(
'next'
)
const
Router
=
require
(
'koa-router'
)
const
Router
=
require
(
'koa-router'
)
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
app
=
next
({
dev
})
const
app
=
next
({
dev
})
const
handle
=
app
.
getRequestHandler
()
const
handle
=
app
.
getRequestHandler
()
...
@@ -32,8 +33,8 @@ app.prepare()
...
@@ -32,8 +33,8 @@ app.prepare()
})
})
server
.
use
(
router
.
routes
())
server
.
use
(
router
.
routes
())
server
.
listen
(
3000
,
(
err
)
=>
{
server
.
listen
(
port
,
(
err
)
=>
{
if
(
err
)
throw
err
if
(
err
)
throw
err
console
.
log
(
'> Ready on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
examples/custom-server-micro/server.js
View file @
ba65b07d
...
@@ -3,6 +3,7 @@ const match = require('micro-route/match')
...
@@ -3,6 +3,7 @@ const match = require('micro-route/match')
const
{
parse
}
=
require
(
'url'
)
const
{
parse
}
=
require
(
'url'
)
const
next
=
require
(
'next'
)
const
next
=
require
(
'next'
)
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
app
=
next
({
dev
})
const
app
=
next
({
dev
})
const
handle
=
app
.
getRequestHandler
()
const
handle
=
app
.
getRequestHandler
()
...
@@ -21,8 +22,8 @@ const server = micro(async (req, res) => {
...
@@ -21,8 +22,8 @@ const server = micro(async (req, res) => {
})
})
app
.
prepare
().
then
(()
=>
{
app
.
prepare
().
then
(()
=>
{
server
.
listen
(
3000
,
err
=>
{
server
.
listen
(
port
,
err
=>
{
if
(
err
)
throw
err
if
(
err
)
throw
err
console
.
log
(
'> Ready on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
examples/custom-server/server.js
View file @
ba65b07d
...
@@ -2,6 +2,7 @@ const { createServer } = require('http')
...
@@ -2,6 +2,7 @@ const { createServer } = require('http')
const
{
parse
}
=
require
(
'url'
)
const
{
parse
}
=
require
(
'url'
)
const
next
=
require
(
'next'
)
const
next
=
require
(
'next'
)
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
app
=
next
({
dev
})
const
app
=
next
({
dev
})
const
handle
=
app
.
getRequestHandler
()
const
handle
=
app
.
getRequestHandler
()
...
@@ -20,8 +21,8 @@ app.prepare()
...
@@ -20,8 +21,8 @@ app.prepare()
handle
(
req
,
res
,
parsedUrl
)
handle
(
req
,
res
,
parsedUrl
)
}
}
})
})
.
listen
(
3000
,
(
err
)
=>
{
.
listen
(
port
,
(
err
)
=>
{
if
(
err
)
throw
err
if
(
err
)
throw
err
console
.
log
(
'> Ready on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
examples/page-transitions/server.js
View file @
ba65b07d
...
@@ -3,7 +3,7 @@ const routes = require('./routes')
...
@@ -3,7 +3,7 @@ const routes = require('./routes')
const
express
=
require
(
'express'
)
const
express
=
require
(
'express'
)
const
compression
=
require
(
'compression'
)
const
compression
=
require
(
'compression'
)
const
port
=
p
rocess
.
env
.
PORT
||
3000
const
port
=
p
arseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
app
=
next
({
dev
})
const
app
=
next
({
dev
})
...
...
examples/parameterized-routing/server.js
View file @
ba65b07d
...
@@ -3,6 +3,7 @@ const { parse } = require('url')
...
@@ -3,6 +3,7 @@ const { parse } = require('url')
const
next
=
require
(
'next'
)
const
next
=
require
(
'next'
)
const
pathMatch
=
require
(
'path-match'
)
const
pathMatch
=
require
(
'path-match'
)
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
app
=
next
({
dev
})
const
app
=
next
({
dev
})
const
handle
=
app
.
getRequestHandler
()
const
handle
=
app
.
getRequestHandler
()
...
@@ -23,8 +24,8 @@ app.prepare()
...
@@ -23,8 +24,8 @@ app.prepare()
// i.e. /blog/foo?show-comments=true
// i.e. /blog/foo?show-comments=true
app
.
render
(
req
,
res
,
'/blog'
,
Object
.
assign
(
params
,
query
))
app
.
render
(
req
,
res
,
'/blog'
,
Object
.
assign
(
params
,
query
))
})
})
.
listen
(
3000
,
(
err
)
=>
{
.
listen
(
port
,
(
err
)
=>
{
if
(
err
)
throw
err
if
(
err
)
throw
err
console
.
log
(
'> Ready on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
examples/root-static-files/server.js
View file @
ba65b07d
...
@@ -3,6 +3,7 @@ const { parse } = require('url')
...
@@ -3,6 +3,7 @@ const { parse } = require('url')
const
next
=
require
(
'next'
)
const
next
=
require
(
'next'
)
const
{
join
}
=
require
(
'path'
)
const
{
join
}
=
require
(
'path'
)
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
app
=
next
({
dev
})
const
app
=
next
({
dev
})
const
handle
=
app
.
getRequestHandler
()
const
handle
=
app
.
getRequestHandler
()
...
@@ -23,8 +24,8 @@ app.prepare()
...
@@ -23,8 +24,8 @@ app.prepare()
handle
(
req
,
res
,
parsedUrl
)
handle
(
req
,
res
,
parsedUrl
)
}
}
})
})
.
listen
(
3000
,
(
err
)
=>
{
.
listen
(
port
,
(
err
)
=>
{
if
(
err
)
throw
err
if
(
err
)
throw
err
console
.
log
(
'> Ready on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
examples/ssr-caching/server.js
View file @
ba65b07d
...
@@ -2,6 +2,7 @@ const express = require('express')
...
@@ -2,6 +2,7 @@ const express = require('express')
const
next
=
require
(
'next'
)
const
next
=
require
(
'next'
)
const
LRUCache
=
require
(
'lru-cache'
)
const
LRUCache
=
require
(
'lru-cache'
)
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
app
=
next
({
dir
:
'.'
,
dev
})
const
app
=
next
({
dir
:
'.'
,
dev
})
const
handle
=
app
.
getRequestHandler
()
const
handle
=
app
.
getRequestHandler
()
...
@@ -30,9 +31,9 @@ app.prepare()
...
@@ -30,9 +31,9 @@ app.prepare()
return
handle
(
req
,
res
)
return
handle
(
req
,
res
)
})
})
server
.
listen
(
3000
,
(
err
)
=>
{
server
.
listen
(
port
,
(
err
)
=>
{
if
(
err
)
throw
err
if
(
err
)
throw
err
console
.
log
(
'> Ready on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
...
...
examples/using-inferno/server.js
View file @
ba65b07d
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
moduleAlias
=
require
(
'module-alias'
)
const
moduleAlias
=
require
(
'module-alias'
)
...
@@ -22,8 +23,8 @@ app.prepare()
...
@@ -22,8 +23,8 @@ app.prepare()
const
parsedUrl
=
parse
(
req
.
url
,
true
)
const
parsedUrl
=
parse
(
req
.
url
,
true
)
handle
(
req
,
res
,
parsedUrl
)
handle
(
req
,
res
,
parsedUrl
)
})
})
.
listen
(
3000
,
(
err
)
=>
{
.
listen
(
port
,
(
err
)
=>
{
if
(
err
)
throw
err
if
(
err
)
throw
err
console
.
log
(
'> Ready on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
examples/using-preact/server.js
View file @
ba65b07d
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
moduleAlias
=
require
(
'module-alias'
)
const
moduleAlias
=
require
(
'module-alias'
)
...
@@ -21,8 +22,8 @@ app.prepare()
...
@@ -21,8 +22,8 @@ app.prepare()
const
parsedUrl
=
parse
(
req
.
url
,
true
)
const
parsedUrl
=
parse
(
req
.
url
,
true
)
handle
(
req
,
res
,
parsedUrl
)
handle
(
req
,
res
,
parsedUrl
)
})
})
.
listen
(
3000
,
(
err
)
=>
{
.
listen
(
port
,
(
err
)
=>
{
if
(
err
)
throw
err
if
(
err
)
throw
err
console
.
log
(
'> Ready on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
examples/with-custom-reverse-proxy/server.es6.js
View file @
ba65b07d
...
@@ -10,7 +10,7 @@ const devProxy = {
...
@@ -10,7 +10,7 @@ const devProxy = {
}
}
}
}
const
port
=
p
rocess
.
env
.
PORT
||
3000
const
port
=
p
arseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
env
=
process
.
env
.
NODE_ENV
const
env
=
process
.
env
.
NODE_ENV
const
dev
=
env
!==
'production'
const
dev
=
env
!==
'production'
const
app
=
next
({
const
app
=
next
({
...
...
examples/with-firebase-authentication/server.js
View file @
ba65b07d
...
@@ -5,6 +5,7 @@ const FileStore = require('session-file-store')(session)
...
@@ -5,6 +5,7 @@ const FileStore = require('session-file-store')(session)
const
next
=
require
(
'next'
)
const
next
=
require
(
'next'
)
const
admin
=
require
(
'firebase-admin'
)
const
admin
=
require
(
'firebase-admin'
)
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
app
=
next
({
dev
})
const
app
=
next
({
dev
})
const
handle
=
app
.
getRequestHandler
()
const
handle
=
app
.
getRequestHandler
()
...
@@ -56,8 +57,8 @@ app.prepare()
...
@@ -56,8 +57,8 @@ app.prepare()
return
handle
(
req
,
res
)
return
handle
(
req
,
res
)
})
})
server
.
listen
(
3000
,
(
err
)
=>
{
server
.
listen
(
port
,
(
err
)
=>
{
if
(
err
)
throw
err
if
(
err
)
throw
err
console
.
log
(
'> Ready on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
examples/with-mobx/server.js
View file @
ba65b07d
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
{
createServer
}
=
require
(
'http'
)
const
{
createServer
}
=
require
(
'http'
)
...
@@ -13,8 +14,8 @@ app.prepare().then(() => {
...
@@ -13,8 +14,8 @@ app.prepare().then(() => {
createServer
((
req
,
res
)
=>
{
createServer
((
req
,
res
)
=>
{
const
parsedUrl
=
parse
(
req
.
url
,
true
)
const
parsedUrl
=
parse
(
req
.
url
,
true
)
handle
(
req
,
res
,
parsedUrl
)
handle
(
req
,
res
,
parsedUrl
)
}).
listen
(
3000
,
err
=>
{
}).
listen
(
port
,
err
=>
{
if
(
err
)
throw
err
if
(
err
)
throw
err
console
.
log
(
'> Ready on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
examples/with-next-routes/server.js
View file @
ba65b07d
...
@@ -2,6 +2,7 @@ const { createServer } = require('http')
...
@@ -2,6 +2,7 @@ const { createServer } = require('http')
const
next
=
require
(
'next'
)
const
next
=
require
(
'next'
)
const
routes
=
require
(
'./routes'
)
const
routes
=
require
(
'./routes'
)
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
app
=
next
({
dev
})
const
app
=
next
({
dev
})
const
handler
=
routes
.
getRequestHandler
(
app
)
const
handler
=
routes
.
getRequestHandler
(
app
)
...
@@ -9,8 +10,8 @@ const handler = routes.getRequestHandler(app)
...
@@ -9,8 +10,8 @@ const handler = routes.getRequestHandler(app)
app
.
prepare
()
app
.
prepare
()
.
then
(()
=>
{
.
then
(()
=>
{
createServer
(
handler
)
createServer
(
handler
)
.
listen
(
3000
,
(
err
)
=>
{
.
listen
(
port
,
(
err
)
=>
{
if
(
err
)
throw
err
if
(
err
)
throw
err
console
.
log
(
'> Ready on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
examples/with-pkg/server.js
View file @
ba65b07d
...
@@ -2,6 +2,7 @@ const { createServer } = require('http')
...
@@ -2,6 +2,7 @@ const { createServer } = require('http')
const
{
parse
}
=
require
(
'url'
)
const
{
parse
}
=
require
(
'url'
)
const
next
=
require
(
'next'
)
const
next
=
require
(
'next'
)
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
app
=
next
({
dev
})
const
app
=
next
({
dev
})
const
handle
=
app
.
getRequestHandler
()
const
handle
=
app
.
getRequestHandler
()
...
@@ -9,8 +10,8 @@ const handle = app.getRequestHandler()
...
@@ -9,8 +10,8 @@ const handle = app.getRequestHandler()
app
.
prepare
()
app
.
prepare
()
.
then
(()
=>
{
.
then
(()
=>
{
createServer
((
req
,
res
)
=>
handle
(
req
,
res
,
parse
(
req
.
url
,
true
).
pathname
))
createServer
((
req
,
res
)
=>
handle
(
req
,
res
,
parse
(
req
.
url
,
true
).
pathname
))
.
listen
(
3000
,
(
err
)
=>
{
.
listen
(
port
,
(
err
)
=>
{
if
(
err
)
throw
err
if
(
err
)
throw
err
console
.
log
(
'> Ready on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
examples/with-pretty-url-routing/server.js
View file @
ba65b07d
...
@@ -2,9 +2,9 @@ const express = require('express')
...
@@ -2,9 +2,9 @@ const express = require('express')
const
next
=
require
(
'next'
)
const
next
=
require
(
'next'
)
const
Router
=
require
(
'./routes'
).
Router
const
Router
=
require
(
'./routes'
).
Router
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
app
=
next
({
dev
})
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
app
=
next
({
dev
})
const
handle
=
app
.
getRequestHandler
()
const
handle
=
app
.
getRequestHandler
()
app
.
prepare
()
app
.
prepare
()
...
...
examples/with-react-i18next/server.js
View file @
ba65b07d
...
@@ -2,6 +2,7 @@ const express = require('express')
...
@@ -2,6 +2,7 @@ const express = require('express')
const
path
=
require
(
'path'
)
const
path
=
require
(
'path'
)
const
next
=
require
(
'next'
)
const
next
=
require
(
'next'
)
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
app
=
next
({
dev
})
const
app
=
next
({
dev
})
const
handle
=
app
.
getRequestHandler
()
const
handle
=
app
.
getRequestHandler
()
...
@@ -40,9 +41,9 @@ i18n
...
@@ -40,9 +41,9 @@ i18n
// use next.js
// use next.js
server
.
get
(
'*'
,
(
req
,
res
)
=>
handle
(
req
,
res
))
server
.
get
(
'*'
,
(
req
,
res
)
=>
handle
(
req
,
res
))
server
.
listen
(
3000
,
(
err
)
=>
{
server
.
listen
(
port
,
(
err
)
=>
{
if
(
err
)
throw
err
if
(
err
)
throw
err
console
.
log
(
'> Ready on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
})
})
examples/with-react-intl/server.js
View file @
ba65b07d
...
@@ -11,6 +11,7 @@ const accepts = require('accepts')
...
@@ -11,6 +11,7 @@ const accepts = require('accepts')
const
glob
=
require
(
'glob'
)
const
glob
=
require
(
'glob'
)
const
next
=
require
(
'next'
)
const
next
=
require
(
'next'
)
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
app
=
next
({
dev
})
const
app
=
next
({
dev
})
const
handle
=
app
.
getRequestHandler
()
const
handle
=
app
.
getRequestHandler
()
...
@@ -46,8 +47,8 @@ app.prepare().then(() => {
...
@@ -46,8 +47,8 @@ app.prepare().then(() => {
req
.
localeDataScript
=
getLocaleDataScript
(
locale
)
req
.
localeDataScript
=
getLocaleDataScript
(
locale
)
req
.
messages
=
dev
?
{}
:
getMessages
(
locale
)
req
.
messages
=
dev
?
{}
:
getMessages
(
locale
)
handle
(
req
,
res
)
handle
(
req
,
res
)
}).
listen
(
3000
,
(
err
)
=>
{
}).
listen
(
port
,
(
err
)
=>
{
if
(
err
)
throw
err
if
(
err
)
throw
err
console
.
log
(
'> Read on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
examples/with-socket.io/server.js
View file @
ba65b07d
...
@@ -3,6 +3,7 @@ const server = require('http').Server(app)
...
@@ -3,6 +3,7 @@ const server = require('http').Server(app)
const
io
=
require
(
'socket.io'
)(
server
)
const
io
=
require
(
'socket.io'
)(
server
)
const
next
=
require
(
'next'
)
const
next
=
require
(
'next'
)
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
nextApp
=
next
({
dev
})
const
nextApp
=
next
({
dev
})
const
nextHandler
=
nextApp
.
getRequestHandler
()
const
nextHandler
=
nextApp
.
getRequestHandler
()
...
@@ -27,8 +28,8 @@ nextApp.prepare().then(() => {
...
@@ -27,8 +28,8 @@ nextApp.prepare().then(() => {
return
nextHandler
(
req
,
res
)
return
nextHandler
(
req
,
res
)
})
})
server
.
listen
(
3000
,
(
err
)
=>
{
server
.
listen
(
port
,
(
err
)
=>
{
if
(
err
)
throw
err
if
(
err
)
throw
err
console
.
log
(
'> Ready on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
examples/with-static-export/server.js
View file @
ba65b07d
const
express
=
require
(
'express'
)
const
express
=
require
(
'express'
)
const
next
=
require
(
'next'
)
const
next
=
require
(
'next'
)
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
app
=
next
({
dev
})
const
app
=
next
({
dev
})
const
handle
=
app
.
getRequestHandler
()
const
handle
=
app
.
getRequestHandler
()
...
@@ -20,8 +21,8 @@ app.prepare()
...
@@ -20,8 +21,8 @@ app.prepare()
return
handle
(
req
,
res
)
return
handle
(
req
,
res
)
})
})
server
.
listen
(
3000
,
(
err
)
=>
{
server
.
listen
(
port
,
(
err
)
=>
{
if
(
err
)
throw
err
if
(
err
)
throw
err
console
.
log
(
'> Ready on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
examples/with-sw-precache/server.js
View file @
ba65b07d
...
@@ -3,6 +3,7 @@ const { join } = require('path')
...
@@ -3,6 +3,7 @@ const { join } = require('path')
const
{
parse
}
=
require
(
'url'
)
const
{
parse
}
=
require
(
'url'
)
const
next
=
require
(
'next'
)
const
next
=
require
(
'next'
)
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
app
=
next
({
dev
})
const
app
=
next
({
dev
})
const
handle
=
app
.
getRequestHandler
()
const
handle
=
app
.
getRequestHandler
()
...
@@ -20,8 +21,8 @@ app.prepare()
...
@@ -20,8 +21,8 @@ app.prepare()
handle
(
req
,
res
,
parsedUrl
)
handle
(
req
,
res
,
parsedUrl
)
}
}
})
})
.
listen
(
3000
,
(
err
)
=>
{
.
listen
(
port
,
(
err
)
=>
{
if
(
err
)
throw
err
if
(
err
)
throw
err
console
.
log
(
'> Ready on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
examples/with-url-object-routing/server.js
View file @
ba65b07d
...
@@ -3,6 +3,7 @@ const { parse } = require('url')
...
@@ -3,6 +3,7 @@ const { parse } = require('url')
const
next
=
require
(
'next'
)
const
next
=
require
(
'next'
)
const
pathMatch
=
require
(
'path-match'
)
const
pathMatch
=
require
(
'path-match'
)
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
const
app
=
next
({
dev
})
const
app
=
next
({
dev
})
const
handle
=
app
.
getRequestHandler
()
const
handle
=
app
.
getRequestHandler
()
...
@@ -21,8 +22,8 @@ app.prepare()
...
@@ -21,8 +22,8 @@ app.prepare()
app
.
render
(
req
,
res
,
'/about'
,
params
)
app
.
render
(
req
,
res
,
'/about'
,
params
)
})
})
.
listen
(
3000
,
(
err
)
=>
{
.
listen
(
port
,
(
err
)
=>
{
if
(
err
)
throw
err
if
(
err
)
throw
err
console
.
log
(
'> Ready on http://localhost:3000'
)
console
.
log
(
`> Ready on http://localhost:
${
port
}
`
)
})
})
})
})
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