mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
Add example of programmatic usage
This commit is contained in:
parent
28f549903b
commit
528ba280f8
1
examples/custom-server/nuxt.config.js
Normal file
1
examples/custom-server/nuxt.config.js
Normal file
@ -0,0 +1 @@
|
||||
module.exports = {}
|
12
examples/custom-server/package.json
Normal file
12
examples/custom-server/package.json
Normal 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"
|
||||
}
|
||||
}
|
24
examples/custom-server/server.js
Normal file
24
examples/custom-server/server.js
Normal 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)
|
Loading…
Reference in New Issue
Block a user