2016-09-26 146 views
0

靜態文件這是我的項目結構:快遞:服務無法正常工作

-backend 
-server.js 
-www 
-index.html 
-app.css 
-bundle.js 

我越來越問題,快遞不能夠起到與具有網址的靜態文件2+斜線這樣

localhost:3000/product/1 

但它工作正常的網址只有1條斜線:發生

localhost:3000/register 
localhost:3000/home 

問題,因爲它總是試圖

本地主機:3000 /產品/ 1/app.css

本地主機:3000 /產品/ 1/bundle.js

時候去

localhost:3000/product/1

這是我在server.js配置:

app.use(express.static(path.resolve(__dirname, '../www'))); 
app.get('*', function (request, response){ 
    response.sendFile(path.resolve(__dirname, '../www', 'index.html')) 
}); 
+1

確保在HTML中鏈接到「/app.css」而不是「app.css」。後者將在當前URL而不是根目錄下查找app.css。這聽起來不像你的靜態資產的問題。 – danneu

+1

同意@danneu。如果使用/filename.ext引用帶有根環境的靜態文件,那麼一切都應該正常工作。 –

+0

我實際上在我的索引文件中使用「./app.css」和「./bundle.js」。我認爲這不應該導致問題。 – sharius2301

回答

0

我所用 「./bundle.js」,並在index.html的 「./app.css」。更改爲「/bundle.js」和「/app.cs」並使其工作。感謝下的評論!