在Heroku上部署Nodej无法为位于子文件夹中的静态文件提供服务 [英] Deploy Nodejs on Heroku fails serving static files located in subfolders
问题描述
我有以下配置
code> app.use(express.static(__ dirname +'/ htdocs'));
它工作正常,除非我尝试提供位于子文件夹中的静态文件。
www.example.com/bar.js //这可以提供文件/htdocs/bar.js
b
我忘了说在本地环境下,一切都很好,可能是与heroku有关的东西,但是找不到原因。有人有这个问题吗?解决方案?
谢谢!
解决方案最后我找到了解决方案。
我解决了在我的package.json中添加了npm版本。
{
name:bla,
version:0.0.1,
dependencies:{
express:3.2。 6
},
engines:{
node:0.10.11,
npm:1.2.25
}
}
I'm deploying a NodeJs application using Heroku. Everything works fine except a little issue serving static files.
I have the following configuration
app.use(express.static(__dirname + '/htdocs'));
It works fine except when I try to serve static files located in sub folders.
www.example.com/bar.js // this serves the file /htdocs/bar.js
www.example.com/foo/bar.js // this can't find the file /htdocs/foo/bar.js
I forgot to say that on my local environment everything works fine, might be something with heroku but I can't find the reason. Did someone had this problem before? Solutions?
Thanks!
解决方案Finally I found the solution.
I solved that just adding the npm version in my package.json.
{ "name": "bla", "version": "0.0.1", "dependencies": { "express": "3.2.6" }, "engines": { "node": "0.10.11", "npm": "1.2.25" } }
这篇关于在Heroku上部署Nodej无法为位于子文件夹中的静态文件提供服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!