mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
2c2d961844
* Added Koa example * Linted koa example
35 lines
773 B
JavaScript
35 lines
773 B
JavaScript
const Koa = require('koa')
|
|
const next = require('next')
|
|
const Router = require('koa-router')
|
|
|
|
const dev = process.env.NODE_ENV !== 'production'
|
|
const app = next({ dev })
|
|
const handle = app.getRequestHandler()
|
|
|
|
app.prepare()
|
|
.then(() => {
|
|
const server = new Koa()
|
|
const router = new Router()
|
|
|
|
router.get('/a', function *() {
|
|
app.render(this.req, this.res, '/b', this.query)
|
|
this.respond = false
|
|
})
|
|
|
|
router.get('/b', function *() {
|
|
app.render(this.req, this.res, '/a', this.query)
|
|
this.respond = false
|
|
})
|
|
|
|
router.get('*', function *() {
|
|
handle(this.req, this.res)
|
|
this.respond = false
|
|
})
|
|
|
|
server.use(router.routes())
|
|
server.listen(3000, (err) => {
|
|
if (err) throw err
|
|
console.log('> Ready on http://localhost:3000')
|
|
})
|
|
})
|