diff --git a/examples/custom-server/nuxt.config.js b/examples/custom-server/nuxt.config.js new file mode 100644 index 0000000000..4ba52ba2c8 --- /dev/null +++ b/examples/custom-server/nuxt.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/examples/custom-server/package.json b/examples/custom-server/package.json new file mode 100644 index 0000000000..9fbc00b272 --- /dev/null +++ b/examples/custom-server/package.json @@ -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" + } +} diff --git a/examples/custom-server/server.js b/examples/custom-server/server.js new file mode 100644 index 0000000000..0e82f3973c --- /dev/null +++ b/examples/custom-server/server.js @@ -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)