Tuesday, 6 June 2017

Koa.js route() is not a function

I just made simple koa app that returns rss xml by tag using parameter. and seems like middleware can't read router from router file. I have no idea why It doesn't work. I'm running this app.js with babel-node. and It keeps saying this error below

app.use((0, _koaLogger2.default)()).use((0, _routes2.default)());
                                                             ^
TypeError: (0 , _routes2.default) is not a function

route/index.js

import Router from 'koa-router'
const router = new Router({ prefix: '/'})

router.get('/:tag', async (ctx, next) => 
    (ctx.body = await rssGenerator(this.param.tag)))

export default router

app.js

import Koa from 'koa'
import logger from 'koa-logger'

import routes from './routes'

const app = new Koa()
const port = process.env.PORT || 3000

app
  .use(logger())
  .use(routes())

app.listen(port, () => console.log("[!] Server STARTED"))



via Phillip YS

No comments:

Post a Comment