似乎无法使用节点js将css和js文件链接到heroku中的index.html

时间:2016-11-22 19:22:34

标签: javascript node.js express heroku

我的app.js文件看起来像这样,我试图让我的根点指向一个tic tac toe游戏。

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>

我在控制台中收到这些错误。 enter image description here

1 个答案:

答案 0 :(得分:1)

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

尝试使用上面的行而不是

app.use(express.static('public'));
相关问题