1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

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

This commit is contained in:
Brikou CARRE 2017-08-10 20:15:46 +02:00 committed by Tim Neutkens
parent d0b95d9bda
commit ba65b07dff
23 changed files with 64 additions and 44 deletions

View file

@ -1,6 +1,7 @@
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()
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}`)
}) })
}) })

View file

@ -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 = [
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()
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}`)
}) })
}) })
}) })

View file

@ -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()
}) })
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}`)
}) })
}) })

View file

@ -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) => {
}) })
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}`)
}) })
}) })

View file

@ -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()
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}`)
}) })
}) })

View file

@ -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 = process.env.PORT || 3000 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 })

View file

@ -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()
// 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}`)
}) })
}) })

View file

@ -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()
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}`)
}) })
}) })

View file

@ -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()
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}`)
}) })
}) })

View file

@ -1,3 +1,4 @@
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()
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}`)
}) })
}) })

View file

@ -1,3 +1,4 @@
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()
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}`)
}) })
}) })

View file

@ -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 env = process.env.NODE_ENV
const dev = env !== 'production' const dev = env !== 'production'
const app = next({ const app = next({

View file

@ -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()
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}`)
}) })
}) })

View file

@ -1,3 +1,4 @@
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(() => {
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}`)
}) })
}) })

View file

@ -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)
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}`)
}) })
}) })

View file

@ -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()
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}`)
}) })
}) })

View file

@ -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()

View file

@ -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
// 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}`)
}) })
}) })
}) })

View file

@ -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(() => {
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}`)
}) })
}) })

View file

@ -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(() => {
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}`)
}) })
}) })

View file

@ -1,6 +1,7 @@
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()
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}`)
}) })
}) })

View file

@ -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()
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}`)
}) })
}) })

View file

@ -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()
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}`)
}) })
}) })