Can I use nuxt.js with Koa
When I use app.use(nuxt.render), it throws an error says
app.use() requires a generator function
Are there any other ways to use nuxt.js with Koa?
a middleware for koa would need to be created. most of the time, you can wrap the express middleware to match what koa needs. checkout https://github.com/koajs/koa/blob/master/docs/guide.md
Hi, It works fine with this code: app.js
var app = require('koa')()
var Nuxt = require('nuxt')
var config = require('./nuxt.config.js')
config.dev = !(app.env === 'production')
var nuxt = new Nuxt(config)
// Build only in dev mode
if (config.dev) {
nuxt.build()
.catch((error) => {
console.error(error) // eslint-disable-line no-console
process.exit(1)
})
}
app.use(function * () {
this.status = 200 // koa defaults to 404 when it sees that status is unset
yield nuxt.render(this.req, this.res)
})
app.listen(3000)
@alexchopin @Atinux koa is not recommended to use req.end()
When using nuxt.render and koa-session, it often throws errors
Can't set headers after they are sent.
Almost all koa session modules can not be used
@chen-zeyu, thank you so much for contributing this fact! Have been knocking my head against this error all day, since the root call is obscured by all of the ES7 shim junk. Have you managed to find a workaround for this? I agree, calling res.end() is incredibly presumptuous for a middleware-based framework.
See #1206 for a workaround for Nuxt 1.0 API changes.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.