Google Groups

Re: [Express-js] express.static :: namespacing static folders with URL's


TJ Holowaychuk Jul 3, 2011 10:23 AM
Posted in group: Express
thanks man! appreciate it. It will be getting a bit better for 3.x :D need to start working on that soon

-- 
TJ Holowaychuk

On Sunday, July 3, 2011 at 10:22 AM, Phil Cockfield wrote:

Beautiful!  Figured there's be a way to do this nicely.

Your API design on Express is deeply elegant Tj.



On Sun, Jul 3, 2011 at 8:50 AM, TJ Holowaychuk <t...@vision-media.ca> wrote:
app.use('/foo', express.static(__dirname + '/public'));

GET /foo/javascripts/jquery.js

etc

Connect has this concept of "mounting" built in, where the middleware is routed based on it, however does not see the prefix given, so static() treats this request as "/javascripts/jquery.js"

-- 
TJ Holowaychuk

On Saturday, July 2, 2011 at 9:33 PM, Phil Cockfield wrote:

CONTEXT:

With [express.static] doing something like this:

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

Will allow the [public] folder to server static assets from the URL
starting at /

----

QUESTION:

But say I have another static resources folder I want to open up,
which is organized somewhere else within the project (for instance,
within a module within the node_modules folder).

Say I wanted to have resources within this other static folder come
off URL's starting at:

/foo/

How would I do that? When I use [express.static] multiple times, I
see that those folders all start at the root of the URL.

I guess I could namespace by putting everything within a named folder
within the actual folder I'm passing to [express.static], but is there
a more elegant way to do this - like pass a URL argument to app.use?

Thanks guys!

--
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.

--
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.

--
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.