这是我的文件结构...
[... root] /src/server.js
[... root] /src/public/images/some_type/some_image.png
[... root] /src/views/index.js(使用EJS模板渲染视图...模板引擎工作正常)
这是代码...
server.js:
server.use('/public',express.static(path.join(__dirname,'public')))
index.js:
<img src="../public/images/some_type/some_image.png">
我在浏览器中遇到此错误:
Failed to load resource: the server responded with a status of 404 (Not Found)
在本地托管的开发环境中,一切正常。推送到Heroku服务器时中断。有人知道为什么会这样吗?
在阅读文档时,我不明白为什么我的设置无法正常工作...
“ ...您提供给express.static函数的路径是相对于您启动节点进程的目录的。”
我的节点进程不是从服务器所在的位置(即src / server.js)启动的吗?即使我确实设置为“错误”,为什么在开发环境中可以正常工作,而不托管prod env?
我尝试了许多将index.js路径和server.js中的路径更改为无用的组合...
在此先感谢您的帮助