2015-02-23 108 views
1

我正在研究一個小型的Node應用程序,並且工作正常。它需要服務於目錄/source的一些靜態文件。Node.js和Express:「無法GET /」靜態網站

今天,在電腦重啓後,當我訪問我的本地網站時,我所得到的全部是Cannot GET /。自上次工作以來,節點配置中沒有任何更改。

var express = require('express'), 
    app  = express(), 
    path = require('path'), 
    fs  = require('fs'); 

// Load our static site to start with 
app.use(express.static(path.join(__dirname, 'source'))); 

// Start the node server 
app.listen(3000, function() { 
    var host = this.address().address, 
     port = this.address().port; 

    console.log('Serving Atenium at http://%s:%s', host, port); 
}); 

我的文件夾的樣子:

|- app/ 
|-- index.js 
|- source/ 
|-- <static files> 

任何想法,爲什麼這個剛剛停止工作?

+0

是否有'source/index.html'文件或任何東西? – 2015-02-23 18:15:19

+0

是的,'source /'目錄有一個'index.html'文件。 – jnettik 2015-02-23 18:21:35

+0

您能否請您證明您的路線定義在哪裏? – NarendraSoni 2015-02-24 02:35:32

回答

0

你可以在這個過程中更新你的express模塊​​嗎?我相信在Express 4中,靜態內容現在由服務靜態中間件庫處理,這裏可以找到https://github.com/expressjs/serve-static

+0

尚未更新。我使用Express 4.11.2和上面的代碼用於工作。我確實嘗試設置'serve-static',我得到了同樣的結果。 – jnettik 2015-02-23 20:15:10