I am needing to respond to http get requests to serve assets. I am needing help to write a route that matches the following description.
Path Info
- Has a configurable prefix (
basePath
) - Has a segment that maps to a real file in the public folder (
path
) - Form:
[basePath]/[path]
Ex:
http://localhost:3000/app/collage/components/bootstrap/dist/css/bootstrap.min.css
basePath = '/app/collage' # set through CLI arguments when app loads
path = '/components/bootstrap/dist/css/bootstrap.min.css' # Comes from route
What I need:
I need to write a get method that will respond to the above type of URL, read the file and send it to the user. The following obviously doesn't work, but I guess now you know what I am asking for.
@get "#{settings.basePath}/:path", (req, res) ->
res.sendFile __dirname + "public" + req.params.path
NOTE: The above is related to
Attempting to create configurable route for delivering assets.