-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
36 lines (27 loc) · 1.26 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Custom server from official example https://github.com/nuxt/nuxt.js/blob/dev/examples/custom-server/server.js
// We need this because we are on Azure, if is not your case or similar you can
// add to your package.json the script: "start": "cross-env NODE_ENV=production nuxt start"
// Add production as fallback if you haven not configured the environment
process.env.NODE_ENV = process.env.NODE_ENV;
process.env.HOST = process.env.HOST || '127.0.0.1'
process.env.PORT = process.env.PORT || 3000
const app = require('express')()
const { Nuxt, Builder } = require('nuxt')
// Import and set Nuxt.js options
let config = require('./nuxt.config.js')
config.dev = !(process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'preview');
const nuxt = new Nuxt(config)
// Start build process in dev mode
if (config.dev) {
const builder = new Builder(nuxt)
builder.build()
}
// Give nuxt middleware to express
app.use(nuxt.render)
console.log('app is using nuxt renderer')
// Add the nosniff header for every request, per security guidelines
const dontSniffMimetype = require('dont-sniff-mimetype')
app.use(dontSniffMimetype());
// Start express server
app.listen(process.env.PORT, process.env.HOST);
console.log('app is listening on: ', process.env.HOST, process.env.PORT);