Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ease running multiple examples at the same time with process.env.PORT #2753

Merged
merged 1 commit into from
Aug 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions examples/custom-server-express/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const express = require('express')
const next = require('next')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
Expand All @@ -21,8 +22,8 @@ app.prepare()
return handle(req, res)
})

server.listen(3000, (err) => {
server.listen(port, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})
5 changes: 3 additions & 2 deletions examples/custom-server-hapi/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const Hapi = require('hapi')
const Good = require('good')
const { pathWrapper, defaultHandlerWrapper } = require('./next-wrapper')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const server = new Hapi.Server()
Expand All @@ -23,7 +24,7 @@ const pluginOptions = [

app.prepare()
.then(() => {
server.connection({ port: 3000 })
server.connection({ port })
server.register(pluginOptions)
.then(() => {
server.route({
Expand All @@ -48,7 +49,7 @@ app.prepare()
console.log('Error starting server')
console.log(error)
}).then(() => {
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})
})
5 changes: 3 additions & 2 deletions examples/custom-server-koa/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const Koa = require('koa')
const next = require('next')
const Router = require('koa-router')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
Expand Down Expand Up @@ -32,8 +33,8 @@ app.prepare()
})

server.use(router.routes())
server.listen(3000, (err) => {
server.listen(port, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})
5 changes: 3 additions & 2 deletions examples/custom-server-micro/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const match = require('micro-route/match')
const { parse } = require('url')
const next = require('next')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
Expand All @@ -21,8 +22,8 @@ const server = micro(async (req, res) => {
})

app.prepare().then(() => {
server.listen(3000, err => {
server.listen(port, err => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})
5 changes: 3 additions & 2 deletions examples/custom-server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
Expand All @@ -20,8 +21,8 @@ app.prepare()
handle(req, res, parsedUrl)
}
})
.listen(3000, (err) => {
.listen(port, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})
2 changes: 1 addition & 1 deletion examples/page-transitions/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const routes = require('./routes')
const express = require('express')
const compression = require('compression')

const port = process.env.PORT || 3000
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'

const app = next({ dev })
Expand Down
5 changes: 3 additions & 2 deletions examples/parameterized-routing/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { parse } = require('url')
const next = require('next')
const pathMatch = require('path-match')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
Expand All @@ -23,8 +24,8 @@ app.prepare()
// i.e. /blog/foo?show-comments=true
app.render(req, res, '/blog', Object.assign(params, query))
})
.listen(3000, (err) => {
.listen(port, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})
5 changes: 3 additions & 2 deletions examples/root-static-files/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { parse } = require('url')
const next = require('next')
const { join } = require('path')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
Expand All @@ -23,8 +24,8 @@ app.prepare()
handle(req, res, parsedUrl)
}
})
.listen(3000, (err) => {
.listen(port, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})
5 changes: 3 additions & 2 deletions examples/ssr-caching/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require('express')
const next = require('next')
const LRUCache = require('lru-cache')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dir: '.', dev })
const handle = app.getRequestHandler()
Expand Down Expand Up @@ -30,9 +31,9 @@ app.prepare()
return handle(req, res)
})

server.listen(3000, (err) => {
server.listen(port, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})

Expand Down
5 changes: 3 additions & 2 deletions examples/using-inferno/server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const moduleAlias = require('module-alias')

Expand All @@ -22,8 +23,8 @@ app.prepare()
const parsedUrl = parse(req.url, true)
handle(req, res, parsedUrl)
})
.listen(3000, (err) => {
.listen(port, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})
5 changes: 3 additions & 2 deletions examples/using-preact/server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const moduleAlias = require('module-alias')

Expand All @@ -21,8 +22,8 @@ app.prepare()
const parsedUrl = parse(req.url, true)
handle(req, res, parsedUrl)
})
.listen(3000, (err) => {
.listen(port, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})
2 changes: 1 addition & 1 deletion examples/with-custom-reverse-proxy/server.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const devProxy = {
}
}

const port = process.env.PORT || 3000
const port = parseInt(process.env.PORT, 10) || 3000
const env = process.env.NODE_ENV
const dev = env !== 'production'
const app = next({
Expand Down
5 changes: 3 additions & 2 deletions examples/with-firebase-authentication/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const FileStore = require('session-file-store')(session)
const next = require('next')
const admin = require('firebase-admin')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
Expand Down Expand Up @@ -56,8 +57,8 @@ app.prepare()
return handle(req, res)
})

server.listen(3000, (err) => {
server.listen(port, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})
5 changes: 3 additions & 2 deletions examples/with-mobx/server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'

const { createServer } = require('http')
Expand All @@ -13,8 +14,8 @@ app.prepare().then(() => {
createServer((req, res) => {
const parsedUrl = parse(req.url, true)
handle(req, res, parsedUrl)
}).listen(3000, err => {
}).listen(port, err => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})
5 changes: 3 additions & 2 deletions examples/with-next-routes/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ const { createServer } = require('http')
const next = require('next')
const routes = require('./routes')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handler = routes.getRequestHandler(app)

app.prepare()
.then(() => {
createServer(handler)
.listen(3000, (err) => {
.listen(port, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})
5 changes: 3 additions & 2 deletions examples/with-pkg/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()

app.prepare()
.then(() => {
createServer((req, res) => handle(req, res, parse(req.url, true).pathname))
.listen(3000, (err) => {
.listen(port, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})
4 changes: 2 additions & 2 deletions examples/with-pretty-url-routing/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const express = require('express')
const next = require('next')
const Router = require('./routes').Router

const dev = process.env.NODE_ENV !== 'production'
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()

app.prepare()
Expand Down
5 changes: 3 additions & 2 deletions examples/with-react-i18next/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require('express')
const path = require('path')
const next = require('next')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
Expand Down Expand Up @@ -40,9 +41,9 @@ i18n
// use next.js
server.get('*', (req, res) => handle(req, res))

server.listen(3000, (err) => {
server.listen(port, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})
})
5 changes: 3 additions & 2 deletions examples/with-react-intl/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const accepts = require('accepts')
const glob = require('glob')
const next = require('next')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({dev})
const handle = app.getRequestHandler()
Expand Down Expand Up @@ -46,8 +47,8 @@ app.prepare().then(() => {
req.localeDataScript = getLocaleDataScript(locale)
req.messages = dev ? {} : getMessages(locale)
handle(req, res)
}).listen(3000, (err) => {
}).listen(port, (err) => {
if (err) throw err
console.log('> Read on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})
5 changes: 3 additions & 2 deletions examples/with-socket.io/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const server = require('http').Server(app)
const io = require('socket.io')(server)
const next = require('next')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const nextApp = next({ dev })
const nextHandler = nextApp.getRequestHandler()
Expand All @@ -27,8 +28,8 @@ nextApp.prepare().then(() => {
return nextHandler(req, res)
})

server.listen(3000, (err) => {
server.listen(port, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})
5 changes: 3 additions & 2 deletions examples/with-static-export/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const express = require('express')
const next = require('next')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
Expand All @@ -20,8 +21,8 @@ app.prepare()
return handle(req, res)
})

server.listen(3000, (err) => {
server.listen(port, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})
5 changes: 3 additions & 2 deletions examples/with-sw-precache/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { join } = require('path')
const { parse } = require('url')
const next = require('next')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
Expand All @@ -20,8 +21,8 @@ app.prepare()
handle(req, res, parsedUrl)
}
})
.listen(3000, (err) => {
.listen(port, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})
Loading