最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - Heroku(Cedar) + Node + Express + Jade Client-side javascript files in subdirectory work locally with foreman+curl but

programmeradmin4浏览0评论

I am very new to node and heroku and I suspect this is some kind of simple permission issue etc, but I can't seem to track it down.

I have several pure javascript files in a sub-directory one level beneath my root directory where my web.js file is sitting. I have a line in my web.js file to specify the directory

app.use('/heatcanvas',express.static(__dirname+'/heatcanvas'));

If I run my app locally with Heroku Foreman I get the expected js response when I run the following curl mand

 curl localhost:5000/heatcanvas/heatcanvas.js

However when I push to Heroku and hit the corresponsing live url in the browser

www.example/heatcanvas/heatcanvas.js

I receive the following:

 Cannot GET /heatcanvas/heatcanvas.js

If I check Firebug and/or the Heroku logs I see I am actually getting 404 errors for those files even though the pathing should match what is being done locally. It is also worth mentioning that third party javascript is ing over just fine, it is only when the src attribute of the script tag points to my site that there is an issue. What do I need to do to get my scripts to be available?

I am very new to node and heroku and I suspect this is some kind of simple permission issue etc, but I can't seem to track it down.

I have several pure javascript files in a sub-directory one level beneath my root directory where my web.js file is sitting. I have a line in my web.js file to specify the directory

app.use('/heatcanvas',express.static(__dirname+'/heatcanvas'));

If I run my app locally with Heroku Foreman I get the expected js response when I run the following curl mand

 curl localhost:5000/heatcanvas/heatcanvas.js

However when I push to Heroku and hit the corresponsing live url in the browser

www.example./heatcanvas/heatcanvas.js

I receive the following:

 Cannot GET /heatcanvas/heatcanvas.js

If I check Firebug and/or the Heroku logs I see I am actually getting 404 errors for those files even though the pathing should match what is being done locally. It is also worth mentioning that third party javascript is ing over just fine, it is only when the src attribute of the script tag points to my site that there is an issue. What do I need to do to get my scripts to be available?

Share Improve this question asked Apr 28, 2012 at 21:17 kirpskirps 1,3552 gold badges17 silver badges28 bronze badges 4
  • 2 I've never looked into the specifics, but I know that in Rails on Heroku, you put/pile your static assets into root/public. For instance Rails piles /assets/base.sass to /public/stylesheets/base.css. So I think Heroku exposes the public dir as a static accessible dir. You generally can't access arbitrary files on production servers like you may be used to in conventional PHP apps. You'd have to specify a GET route that actually serves up that heatcanvas.js file -- but you wouldn't want to do that. I'm really rusty, but perhaps try to utilize the public dir. – danneu Commented May 7, 2012 at 0:13
  • 1 On the Cedar stack requests are routed to the dyno un-disturbed. So it is up to the app/framework to serve static assets. The only special about the public directory is that the Rails app/framework serves assets from there. Node.js apps will have different structure. – Ryan Daigle Commented Jun 21, 2012 at 0:47
  • Can you please include the output of heroku logs -t during one of these requests? – Ryan Daigle Commented Jun 21, 2012 at 0:47
  • Is your app.use() in an app.configure() block that's not running on Heroku? You do have to specifically run $ heroku config:add NODE_ENV=* for Express to know what environment to use. – swider Commented Jun 30, 2012 at 22:38
Add a ment  | 

1 Answer 1

Reset to default 7

I remend you to use process.cwd() value to get specific directory

process.env.PWD = process.cwd()

at the very beginning of your web.js

let you access files easily.

You can do

app.use('/heatcanvas',express.static(process.env.PWD+'/heatcanvas'));

instead of using

__dirname

Warning: Make sure to execute web.js at the root directory of web.js (Heroku web.js are executed that way)

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论