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); 

この方法では、ルーティングを処理するファイルにアプリケーションを渡しています。お役に立てれば。

関連する問題