2016-11-22 26 views
0

我的app.js文件看起來像這樣,我想讓我的根指向一個tic tac toe遊戲。似乎無法將css和js文件鏈接到使用節點js的heroku中的index.html

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

+0

您可以發佈您的文件結構,嘗試調試這裏發生了什麼 – leofontes

回答

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

嘗試了上述行,而不是

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

路徑是NPM模塊時會有所幫助。 –

+0

只有'__dirname +'/ public'也可以。 –

+0

我加了app.use(express.static(path.join(__ dirname,'public')));而不是 app.use(express.static('public'));不工作。 – crod