Saturday 13 May 2017

Express static file routing

I have been trying to search the proper way to solve this problem, but have had no luck. I am trying to get express.static to point to the same directory, completely ignoring what's happening in the requesting URL. My directory is structured like so:views --view1.hbs --view2.hbs --etc... public --css --main.css --js --main.js --images --bunch --of --images My current static route is set up like so:app.use(express.static(path.join(__dirname, 'public'))); And for routes which come from the root directory, this works as expected. So for example:http://mysite.com/home http://ift.tt/2r4jRnn As soon as I start to add another level to the url, this breaks down. For examplehttp://mysite.com/archive/2 Routes incorrectly to/public/2/folder/resource.xxx Instead of/public/folder/resource.xxx So how do I setup my static file router so that a url such ashttp://mysite.com/any/number/of/levels/into/infinity Always serves static resources from the public folder route directory? I'm pretty new to building this kind of application, so any guidance is appreciated.

Submitted May 13, 2017 at 03:36PM by saabstory88

No comments:

Post a Comment