子目录中没有提供express.static在heroku [英] Subdirectories not being served with express.static in heroku
问题描述
我看到一些非常奇怪的行为,我的某些文件正确地被我的快递/节点服务器返回(使用 express.static()
),但不是子目录下的文件。令人沮丧的事情是,使用节点或工头在本地工作正常,它不会在英雄上工作。 这个要点在这里播放主要文件,我的应用程序结构如下所示: p>
-app
- index.html
- img /
- base.png
- sub /
- sub.png
- 脚本
- base.js
- sub /
- sub.js
- css
- base.css
- sub /
- sub.css
- 服务器
- app.js
index.html和base。*文件都加载正常,只是那个404.的sub。*文件似乎是奇怪的,express.static会走1级深,但是不是2
我尝试了一系列不同的配置,包括这个 stackoverflow answer 。我必须遗漏一些简单的东西。感谢您的帮助。
更新:
当我在console.log上,在heroku上的服务器启动时,我得到:
-
path.join(__ dirname,'../app')
=/ app
-
path.join(__ dirname,'/../app')
=/ app / app
-
path.normalize(path.join(__ dirname, '../ app'))
=/ app / app
-
path.join(process.cwd(),'../ app')
=/ app / app
确保将目录的子目录添加到Git存储库。 p>
您可以使用 heroku运行'ls〜'
来帮助调试问题(通过观察dyno上的文件)。
放置绝对路径并没有为我修复。您的 .gitignore
可能会被排除。
I'm seeing some really odd behavior where some of my files are correctly being returned by my express/node server (using express.static()
), but not files within subdirectories. The frustrating thing is that it works fine using node or foreman locally, it just won't work on heroku. This gist has the main files at play here, and my app structure looks like this:
-app
- index.html
- img/
- base.png
- sub/
- sub.png
- scripts
- base.js
- sub/
- sub.js
- css
- base.css
- sub/
- sub.css
- server
- app.js
The index.html, and base.* files all load fine, it's just the sub.* files that 404. Seems bizarre that express.static would go 1 level deep, but not 2
I've tried a slew of different configurations, including this stackoverflow answer. I have to be missing something simple. Thanks for the help.
UPDATE:
When I console.log the following on server startup on heroku, I get:
path.join(__dirname, '../app')
=/app
path.join(__dirname, '/../app')
=/app/app
path.normalize(path.join(__dirname, '../app'))
=/app/app
path.join(process.cwd(), '../app')
=/app/app
Make sure that the sub directories of your directory are added to your Git repository.
You can use heroku run 'ls ~'
to help debug the issue (by observing the files on the dyno).
Putting the absolute path did not fix it for me. Your .gitignore
may be excluding it.
这篇关于子目录中没有提供express.static在heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!