index.js
import serve from 'koa-static';
import cors from '@koa/cors';
import Koa from 'koa';
import mongoose from './DB/dbConnection';
import requestId from 'koa-requestid';
import Listitems from './models/listDetails';
import BodyParser from "koa-bodyparser";
import orderList from './models/orderDetails';
import router from './routes/routes.js';
const os = require('os');
const app = new Koa();
app.use(serve('.'));
app.use(cors());
app.use(BodyParser());
app.use(requestId());
app.use(router)
app.listen(8080, () => {
console.log('Server started on localhost:8080');
});
routes / routes.js
import Router from 'koa-router';
import OrderCtrl from '../controllers/orderCtrl';
var router = new Router();
router.prefix('/api/order')
router.get('/', OrderCtrl.find);
export default router;
我在创建Rest Api时遇到错误。似乎中间件无法从路由器文件读取路由器。我不知道为什么它不起作用。请帮助我
app.use((0, _routes.default)());
^
TypeError: (0 , _routes.default) is not a function
at Object.<anonymous> (D:\Fullstackweb\new\fullstackweb\src\server/index.js:19:9)