我的app.js文件看起来像这样,我试图让我的想法指向井字游戏。

app.set('port', (process.env.PORT || 5000))


//serve static files in the public directory
app.use(express.static('public'));

// Process application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({
extended: false
}))

// Process application/json
app.use(bodyParser.json())

// Index route
app.get('/', function (req, res) {
res.sendFile('index.html',{root:"./Tic-Tac-Toe"});


})


在我的./Tic-Tac-Toe目录中的index.html中,我正在链接服务器似乎找不到的某些文件。

<link rel = 'stylesheet' type = 'text/css' href = 'ui.css'>
<script src = "jquery-1.10.1.min.js"></script>
<script src = "ui.js"></script>
<script src = "game.js"></script>
<script src = "ai.js"></script>
<script src = "control.js"></script>


我在控制台中收到这些错误。 javascript - 似乎无法使用 Node js将css和js文件链接到heroku中的index.html-LMLPHP

最佳答案

app.use(express.static(path.join(__dirname, 'public')));


尝试以上行而不是

app.use(express.static('public'));

10-05 20:41
查看更多