0
저는 React/Express/Node 세계에서 새로 왔으며 사용자가 작업을 생성하는 로그인과 API를 만들 수있는 앱을 연구 중입니다. TypeError : app.route가 함수가 아닙니다.
나는 동일한 응용 프로그램에서 함께 모두 넣어 노력하고있어,하지만 난 작업 목록에 대한 GET을 호출 할 때이 오류가있어 :TypeError: app.route is not a function
at module.exports (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/server/routes/schedule.js:6:7)
at Layer.handle [as handle_request] (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:317:13)
at /home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:335:12)
at next (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:275:10)
at initialize (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/passport/lib/middleware/initialize.js:53:5)
at Layer.handle [as handle_request] (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:317:13)
at /home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:335:12)
at next (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:275:10)
at urlencodedParser (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/body-parser/lib/types/urlencoded.js:91:7)
at Layer.handle [as handle_request] (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:317:13)
at /home/slauriano/workspace/authentication-in-react-apps/part-2-json-web-token/node_modules/express/lib/router/index.js:284:7
이것은하여 ToDoList의 코드입니다. 경로 폴더의 js :
'use strict';
module.exports = function(app) {
var todoList = require('../controllers/todoListController');
// todoList Routes
app.route('/tasks')
.get(todoList.list_all_tasks)
.post(todoList.create_a_task);
app.route('/tasks/:taskId')
.get(todoList.read_a_task)
.put(todoList.update_a_task)
.delete(todoList.delete_a_task);
};
내가 놓친 것은 무엇입니까? ;) 내 저장소 https://github.com/slaurianodev/agenda-app의
const express = require('express');
const router = new express.Router();
router.get('/dashboard', (req, res) => {
res.status(200).json({
message: "You're authorized to see this secret message."
});
});
module.exports = router;
내가 이것에 대한 어떤 도움을 주셔서 감사합니다 : 즉, 같은 길을 폴더에 제대로 작동 인증 응용 프로그램의 부분의 조각입니다. 이 문제를 복제하고 도울 수 있습니다.
TKS
세르지오
오류가 명확합니다. 당신은'scheduleRoutes'에서 함수를 내 보낸다. 그렇지만'app'을 넘겨주지 않는다. – azium
어떻게 해결할 수 있을까? –