Next-routes: Koa usage

Created on 11 Apr 2017  路  2Comments  路  Source: fridays/next-routes

How do you use next-routes with Koa v2?

Most helpful comment

Here is an example:

const Koa = require('koa')
const next = require('next')
const routes = require('./routes')
const app = next({dev: process.env.NODE_ENV !== 'production'})
const handler = routes.getRequestHandler(app)
const server = new Koa()

app.prepare().then(() => {
  server.use(ctx => {
    ctx.respond = false
    ctx.res.statusCode = 200 // because koa defaults to 404
    handler(ctx.req, ctx.res)
  }).listen(3000)
})

Let me know if you need any help!

All 2 comments

Here is an example:

const Koa = require('koa')
const next = require('next')
const routes = require('./routes')
const app = next({dev: process.env.NODE_ENV !== 'production'})
const handler = routes.getRequestHandler(app)
const server = new Koa()

app.prepare().then(() => {
  server.use(ctx => {
    ctx.respond = false
    ctx.res.statusCode = 200 // because koa defaults to 404
    handler(ctx.req, ctx.res)
  }).listen(3000)
})

Let me know if you need any help!

Works great! Thanks :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

haotangio picture haotangio  路  5Comments

dbenfouzari picture dbenfouzari  路  6Comments

arefaslani picture arefaslani  路  3Comments

adekbadek picture adekbadek  路  4Comments

apapacy picture apapacy  路  4Comments