Add example of programmatic usage

This commit is contained in:
Sebastien Chopin 2017-07-26 18:14:34 +02:00
parent 28f549903b
commit 528ba280f8
3 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1 @@
module.exports = {}

View File

@ -0,0 +1,12 @@
{
"name": "nuxt-custom-server",
"dependencies": {
"express": "^4.15.3",
"nuxt": "^1.0.0-rc1"
},
"scripts": {
"dev": "node server.js",
"build": "nuxt build",
"start": "NODE_ENV=production node server.js"
}
}

View File

@ -0,0 +1,24 @@
const app = require('express')()
const { Nuxt, Builder } = require('nuxt')
const host = process.env.HOST || '127.0.0.1'
const port = process.env.PORT || 3000
// Import and Set Nuxt.js options
let config = require('./nuxt.config.js')
config.dev = !(process.env.NODE_ENV === 'production')
const nuxt = new Nuxt(config)
// Start build process if
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)
console.log('Server listening on ' + host + ':' + port)