Nuxt/examples/custom-server/server.js

26 lines
550 B
JavaScript
Raw Normal View History

2018-03-16 16:12:06 +00:00
import express from 'express'
import { Nuxt, Builder } from 'nuxt'
const app = express()
2017-07-26 16:14:34 +00:00
const host = process.env.HOST || '127.0.0.1'
const port = process.env.PORT || 3000
2017-07-30 17:49:12 +00:00
// Import and set Nuxt.js options
2017-07-26 16:14:34 +00:00
let config = require('./nuxt.config.js')
config.dev = !(process.env.NODE_ENV === 'production')
const nuxt = new Nuxt(config)
2017-07-30 17:49:12 +00:00
// Start build process in dev mode
2017-07-26 16:14:34 +00:00
if (config.dev) {
const builder = new Builder(nuxt)
builder.build()
}
// Give nuxt middleware to express
app.use(nuxt.render)
// Start express server
app.listen(port, host)