2017-09-22 3 views
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

세르지오

+0

오류가 명확합니다. 당신은'scheduleRoutes'에서 함수를 내 보낸다. 그렇지만'app'을 넘겨주지 않는다. – azium

+0

어떻게 해결할 수 있을까? –

답변

0

당신은 응용 프로그램 매개 변수를 사용하여 todoList.js를 호출하고 있습니까? 일반적으로 다른 파일을 라우팅 파일로 사용하면 다음과 같습니다.

var express = require('express'); 
var app = express(); 
var routes = require('<path to file>/todoList.js'); 
routes(app); 

이렇게하면 라우팅을 처리하는 파일에 앱을 전달하게됩니다. 희망이 도움이됩니다.

관련 문제