我试图以不同的方式构造nodejs api,但在尝试导入路由时出现以下错误:
/users/pato/documents/node js-bp-api/node-modules/express/lib/router/index.js:139
调试('dispatching%s%s',req.method,req.url);
^
类型错误:无法读取未定义的属性“method”
express.js文件
.
.
app.use(cors());
app.use(config.api.prefix, apiRoutes());
API路由/索引.js
const todo = require('../api/routes/todo');
const express = require('express');
const apiRoutes = () => {
const app = express.Router();
todo(app);
return app();
};
module.exports = apiRoutes;
TOdo.js路线
const todo = router => {
router.get('/', function(req, res, next) {
res.json({ msg: 'This is CORS-enabled for all origins!' });
});
};