授权后,用户被重定向到聊天的地址http://localhost:3000/home,但是当链接http://localhost:3000/home打开时,在图片中出现错误error,您可以看到错误
代码app.js
app.use(express.static(path.join(__dirname, 'views')));
app.set("view engine", "hbs");
app.use(bodyParser.urlencoded({extended : false}));
app.use(bodyParser.json());
app.use("/", userRouter);
app.use("/signup", signupRouter);
var server = require('http').createServer(app);
var io = require('socket.io')(server);
io.path('/home');
var controller = require('./controllers/chatController.js');
io.on('connection', controller.respond );
路由器
const express = require("express");
const userRouter = express.Router();
var homeController = require('../controllers/homeController.js');
userRouter.get("/home", homeController.home);
homeController.js
let user=require("../models/user.js");
exports.home = function(request, response) {
let data=[request.session.username, request.session.username];
if (request.session.loggedin) {
user.getUser(data).then(function(item){
response.render("index.hbs", {user:item[0]});
});
} else {
response.send('Please login to view this page!');
}
};
我使用车把和socket.io 2.3.0
我了解这是否是路径问题? 该怎么解决?