[英]Why express.static() not load my .js and .css files from correct path?
const express = require('express');
const app = express();
const server = require('http').Server(app);
const io = require('socket.io').listen(server);
const path = require('path');
let lobbies = new Array();
app.use(express.static(path.join(__dirname, '/public')));
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, '/public', 'index.html'));
});
After refreshing page on http://localhost:8081/CreateGame/js/game I get my index.html file but all my .js and .css files trying to get them on http://localhost:8081/CreateGame/js/game.js when it should be http://localhost:8081/js/game I have no idea how I should set this up, thank you for any help.在http://localhost:8081/CreateGame/js/game刷新页面后,我得到了 index.html 文件,但我所有的 .js 和 .css 文件都试图在http://localhost:8081/CreateGame/js/上获取它们game.js当它应该是http://localhost:8081/js/game我不知道我应该如何设置它,谢谢你的帮助。
The problem was witch src path in index.html... I had问题是 index.html 中的女巫 src 路径...我有
<script src="js/game.js"></script>
And it should be like this它应该是这样的
<script src="/js/game.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.