static files not being served

281 views
Skip to first unread message

Brian LeRoux

unread,
May 16, 2010, 2:51:07 AM5/16/10
to Express
Running:
- node 0.1.91
- Express 0.11.0

I'm sure this is a config issue. My app structure:

root
|- public
| '- foo.css
'- server.js

In my config I have:

p = require("path").join(__dirname, "public");
use(Static, { path:p });

But anything in there is 404'ing on me. What am I missing?

(And thx in advance! This is fun btw.)

--
You received this message because you are subscribed to the Google Groups "Express" group.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.

francisco treacy

unread,
May 16, 2010, 4:30:02 PM5/16/10
to expre...@googlegroups.com
Like this?

get('/public/*', function(file){
this.sendfile(__dirname + '/public/' + file)
})



2010/5/16 Brian LeRoux <brian....@gmail.com>:

Aaron Heckmann

unread,
May 16, 2010, 4:56:03 PM5/16/10
to expre...@googlegroups.com
Brian, it looks correct. What is __dirname returning?
--
Aaron
http://clickdummy.net

Brian LeRoux

unread,
May 16, 2010, 7:03:02 PM5/16/10
to expre...@googlegroups.com
@francisco - exactly like that...I'm using a similar hack atm. I
thought use(Static) should generate this automagically?
@aaron - __dirname returning correct value by sys.puts

I've attached an example app that distills the behavior I'm seeing.

thanks for helping guys! Very much appreciated.
StaticFileFail.zip

Guillermo Rauch

unread,
May 16, 2010, 7:13:05 PM5/16/10
to expre...@googlegroups.com
It's better to use gist.github.com for posting examples.
--
Guillermo Rauch
http://devthought.com

Aaron Heckmann

unread,
May 16, 2010, 8:11:16 PM5/16/10
to expre...@googlegroups.com
Brian,

It works fine for me - except for the css file not being included in the layout. :)

If I hit http://localhost:8000/public/app.css it works fine.

If still no luck, try installing node v0.1.94

Brian LeRoux

unread,
May 16, 2010, 8:53:00 PM5/16/10
to expre...@googlegroups.com
Problem: solved. /public was expected in the url unlike rails where it
just goes to root.

@aaron: hilarious! thanks for that url / now I get it.
@Guillermo: thanks for the input. I find multi-file / pathing
situations gists can things worse since they don't really demonstrate
the relative locations of files.



On Sun, May 16, 2010 at 5:11 PM, Aaron Heckmann

vision media [ Tj Holowaychuk ]

unread,
May 16, 2010, 8:57:59 PM5/16/10
to expre...@googlegroups.com
this should probably be documented better i guess. But ya I didnt want to 
do it like rails because it just slows down routing, possibly quiiiiite a lot so its 
a bad practice IMO but ya you get "/public/*" baked in with use(Static)
--
Tj Holowaychuk
Vision Media
President & Creative Lead
Reply all
Reply to author
Forward
0 new messages