Static GitHub Issues

[1206] programatic usage with koa fails since migration from 1.0.0-alpha.4 to v1.0.0-rc3

prev: install starter nuxt error when udate node js version
next: yarn.lock file (module version problem)

This is my koa app that serves nuxt app.

  • if NODE_ENV=production it always serves "OK" and nothing happens on server
  • if NODE_ENV=development it always serves "OK" and in server logs I see that app fetches async data and then there is error UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Can't set headers after they are sent.
  • it works with express
import Koa from 'koa'
import { Nuxt, Builder } from 'nuxt'
import config from './../nuxt.config.js'

const app = new Koa()

config.dev = !(process.env.NODE_ENV === 'production')

const nuxt = new Nuxt(config)

if (config.dev) {
  const builder = new Builder(nuxt)
  builder.build()
}

app.use(async (ctx, next) => {
  ctx.status = 200
  await nuxt.render(ctx.req, ctx.res)
})

app.listen(3000)
console.log('Server listening')

Note that following piece of code is exactly the same I used with nuxt 1.0.0-alpha.4

app.use(async (ctx, next) => {
  ctx.status = 200
  await nuxt.render(ctx.req, ctx.res)
})
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c1063">#c1063</a>)</em></sub></div>