Express app.use()不在单独的文件“ Cannot GET /”中处理路由

时间:2018-07-25 10:59:01

标签: node.js express routing backend

结果为“无法获取/”

两个文件都在同一个文件夹中,如果我直接在app.js文件中使用路由,则它可以工作。 app.js

//ROUTING
var router = require('./index');
app.use('/*', router);
//ROUTING END

index.js

var express = require('express');
var router = new express.Router();
var user = require("./controllers/user");
var products = require("./controllers/products");
router.get("/", products.products_list);
router.get("/user/profile", user.profile);
router.get("/user/signup", user.signup_redirect);
router.get("/user/logout", user.logout_redirect);
router.post("/user/signup", user.signup_post);
router.get("/user/login",user.login_redirect);
router.post("/user/login", user.login_post);

module.exports = router

0 个答案:

没有答案