我正在尝试将不同的url请求路由到不同的目录。现在,我使用的是:
app.use(express.static(root));将所有内容路由到我的项目中的特定目录。我需要能够做的是,只有当请求不是针对其他目录的子集时,才有条件地路由到该目录。示例:
if(route == '/blah1'){
//route to particular folder
}
else if(route == '/blah2'){
//route to a different folder
}
else{
//otherwise use static route
}有什么想法吗?
发布于 2013-01-30 04:47:06
您可以在层次结构中的不同点“挂载”静态中间件。将默认的“catch-all”目录放在末尾:
app.use('/blah1', express.static('/somedir1'));
app.use('/blah2', express.static('/somedir2'));
app.use(express.static('/defaultdir'));参见the express.js documentation。
https://stackoverflow.com/questions/14590987
复制相似问题