我刚刚创建了一个简单的koa应用程序,它通过tag使用参数返回rss xml。而且似乎中间件无法从路由器文件中读取路由器。我不知道为什么它不起作用。我用babel-node运行这个app.js。它一直在说下面的错误
app.use((0, _koaLogger2.default)()).use((0, _routes2.default)());
^
TypeError: (0 , _routes2.default) is not a function
路线/ 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"))
答案 0 :(得分:1)
我在你的代码中看到了2个问题:
首先:你要导入这样的路线:
import routes from './routes'
但在您的代码中,路径为route/index.js
而不是routes
第二:在route/index.js
导出router
export default router
但是您要尝试导入routes