Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Multiple concurrent static hosting contexts

Multiple concurrent static hosting contexts

Problem

If I have a project directory that looks like the following:

/
    custom_assets
        File1.txt
    generic_assets
        File2.txt

Is there a node http server implementation that would allow me to host both directories from the same root url?

For example:

http://localhost/File1.txt

Or

http://localhost/File2.txt

Almost like as if the two directories were merged.

Problem courtesy of: Omega

Solution

ExpressJS which is a popular node web application framework can do it. Using two static middlewares should do the trick.

Your code should look like this:

app.use(express.static(__dirname + '/custom_assets'));
app.use(express.static(__dirname + '/generic_assets'));
Solution courtesy of: drorw

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Multiple concurrent static hosting contexts

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×