Closed digitalit closed 6 years ago
Finally got it working like this in server.js. I hope it can help anyone :)
const { Nuxt, Builder } = require('nuxt')
const bodyParser = require('body-parser')
const session = require('express-session')
const app = require('express')()
// Body parser, to access req.body
app.use(bodyParser.json())
// Sessions to create req.session
app.use(session({
secret: 'super-secret-key',
resave: false,
saveUninitialized: false,
cookie: { maxAge: 60000 }
}))
app.put('/api/todos', function (req, res) {
req.session.todos = req.body.todos
res.json(req.session.todos)
})
// Import and set nuxt.js options
let config = require('./nuxt.config.js')
config.dev = !(process.env.NODE_ENV === 'production')
let nuxt = new Nuxt(config)
// Start build process (only in development)
if (config.dev) {
new Builder(nuxt).build()
}
app.use(nuxt.render)
app.listen(3009)
console.log('Server is listening on http://localhost:3009') // eslint-disable-line no-console
Can someone please tell me how to get this to work?
The correct and complete server.js would be great since there are tons on chunks in different issues and i can't get it to work.