我需要在简单的node.js中使用中间件的以下express.js代码的等效代码。我需要根据url进行一些检查,并希望在自定义中间件中进行检查。与url模式匹配的Node.js
app.get "/api/users/:username", (req,res) ->
req.params.username
我有下面的代码到目前为止,
app.use (req,res,next)->
if url.parse(req.url,true).pathname is '/api/users/:username' #this wont be true as in the link there will be a actual username not ":username"
#my custom check that I want to apply
我没有中间件里面App对象。另外我只想匹配URL模式。 –
@AtaurRehmanAsad第一个解决方案匹配URL模式 – robertklep
是的先生。但我没有中间件的应用程序对象:) –