在Heroku上部署Nodej无法为位于子文件夹中的静态文件提供服务 [英] Deploy Nodejs on Heroku fails serving static files located in subfolders

查看:93
本文介绍了在Heroku上部署Nodej无法为位于子文件夹中的静态文件提供服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Heroku部署NodeJs应用程序。一切正常,除了提供静态文件的一个小问题。



我有以下配置

 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆