最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

快速JS

IT培训 admin 3浏览 0评论

快速JS

我使用ExpressJS 4.x的开发REST Web服务器。我想要做的就是写捕获所有传入的请求,除了开头的那些“/ API / ......”中间件

我可以使用哪种正则表达式?

//This middleware catches everything except the requests addressed to "/api/..."
app.use('<regular_expression>',express.static('public'));

//Not intercepted by the middleware
app.get("/api/foo1",function(req,res)=>{
    ......
})

//Not intercepted by the middleware
app.get("/api/foo2/bar",function(req,res)=>{
    ......
})
回答如下:

根据这一SO answer,您可以使用negative look ahead(他们在Javascript提供):

app.use(/\/((?!api).)*/, app_lookup);

正如你所看到的,正则表达式没有用引号括起来。

快速JS

我使用ExpressJS 4.x的开发REST Web服务器。我想要做的就是写捕获所有传入的请求,除了开头的那些“/ API / ......”中间件

我可以使用哪种正则表达式?

//This middleware catches everything except the requests addressed to "/api/..."
app.use('<regular_expression>',express.static('public'));

//Not intercepted by the middleware
app.get("/api/foo1",function(req,res)=>{
    ......
})

//Not intercepted by the middleware
app.get("/api/foo2/bar",function(req,res)=>{
    ......
})
回答如下:

根据这一SO answer,您可以使用negative look ahead(他们在Javascript提供):

app.use(/\/((?!api).)*/, app_lookup);

正如你所看到的,正则表达式没有用引号括起来。

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论