提交 ba65b07d 编写于 作者: B Brikou CARRE 提交者: Tim Neutkens

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

上级 d0b95d9b
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()
......@@ -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}`)
})
})
......@@ -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()
......@@ -23,7 +24,7 @@ const pluginOptions = [
app.prepare()
.then(() => {
server.connection({ port: 3000 })
server.connection({ port })
server.register(pluginOptions)
.then(() => {
server.route({
......@@ -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}`)
})
})
})
......@@ -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()
......@@ -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}`)
})
})
......@@ -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()
......@@ -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}`)
})
})
......@@ -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()
......@@ -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}`)
})
})
......@@ -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 })
......
......@@ -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()
......@@ -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}`)
})
})
......@@ -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()
......@@ -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}`)
})
})
......@@ -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()
......@@ -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}`)
})
})
......
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const moduleAlias = require('module-alias')
......@@ -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}`)
})
})
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const moduleAlias = require('module-alias')
......@@ -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}`)
})
})
......@@ -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({
......
......@@ -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()
......@@ -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}`)
})
})
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const { createServer } = require('http')
......@@ -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}`)
})
})
......@@ -2,6 +2,7 @@ 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)
......@@ -9,8 +10,8 @@ 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}`)
})
})
......@@ -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()
......@@ -9,8 +10,8 @@ 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}`)
})
})
......@@ -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()
......
......@@ -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()
......@@ -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}`)
})
})
})
......@@ -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()
......@@ -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}`)
})
})
......@@ -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()
......@@ -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}`)
})
})
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()
......@@ -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}`)
})
})
......@@ -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()
......@@ -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}`)
})
})
......@@ -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()
......@@ -21,8 +22,8 @@ app.prepare()
app.render(req, res, '/about', params)
})
.listen(3000, (err) => {
.listen(port, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
console.log(`> Ready on http://localhost:${port}`)
})
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册