Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku(Cedar) + Node + Express + Jade Client-side javascript files in subdirectory work locally with foreman+curl but not when pushed to Heroku

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 command

 curl localhost:5000/heatcanvas/heatcanvas.js

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

www.example.com/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 coming 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?

like image 734
kirps Avatar asked Apr 28 '12 21:04

kirps


1 Answers

I recommend 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)

like image 103
jwchang Avatar answered Oct 17 '22 09:10

jwchang