快递:服务无法正常工作

问题描述:

静态文件这是我的项目结构:快递:服务无法正常工作

-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

我所用 “./bundle.js”,并在index.html的 “./app.css”。更改为“/bundle.js”和“/app.cs”并使其工作。感谢下的评论!