在 Heroku 上部署 Nodejs 无法提供位于子文件夹中的静态文件 [英] Deploy Nodejs on Heroku fails serving static files located in subfolders
问题描述
我正在使用 Heroku 部署一个 NodeJs 应用程序.除了提供静态文件的小问题外,一切正常.
I'm deploying a NodeJs application using Heroku. Everything works fine except a little issue serving static files.
我有以下配置
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//这提供文件/htdocs/bar.js
www.example.com/bar.js // this serves the file /htdocs/bar.js
www.example.com/foo/bar.js//这个找不到文件/htdocs/foo/bar.js
www.example.com/foo/bar.js // this can't find the file /htdocs/foo/bar.js
我忘了说在我的本地环境中一切正常,可能是 heroku 的问题,但我找不到原因.以前有人遇到过这个问题吗?解决方案?
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?
谢谢!
推荐答案
我终于找到了解决方案.
Finally I found the solution.
我解决了在 package.json 中添加 npm 版本的问题.
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 上部署 Nodejs 无法提供位于子文件夹中的静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!