I am trying to route different url requests to different directories. Right now, I am using this:
app.use(express.static(root));
to route everything to a particular directory within my project. What I need to be able to do is conditionally route to that directory ONLY IF the request isn't for a subset of other directories. Example:
if(route == '/blah1'){
//route to particular folder
}
else if(route == '/blah2'){
//route to a different folder
}
else{
//otherwise use static route
}
Any ideas?
You can 'mount' the static middleware at different points in the hierarchy. Place the default 'catch-all' directory at the end:
app.use('/blah1', express.static('/somedir1'));
app.use('/blah2', express.static('/somedir2'));
app.use(express.static('/defaultdir'));