미들웨어에서 사용할 수있는 간단한 node.js에 express.js 코드와 동등한 코드가 필요합니다. URL에 따라 몇 가지 검사를해야하며 사용자 정의 미들웨어에서 수행하려고합니다. 만, GET
요청을 일치 대신 app.get
를 사용하려면URL 패턴과 일치하는 Node.js
app.all '/api/users/:username', (req, res, next) ->
// your custom code here
next();
// followed by any other routes with the same patterns
app.get '/api/users/:username', (req,res) ->
...
:
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
내가 미들웨어 내부 응용 프로그램 개체가 없습니다. 또한 URL 패턴과 일치 시키려고합니다. –
@AtaurRehman 첫 번째 해결책은 URL 패턴과 일치합니다. – robertklep
예. 하지만 midleware에서 응용 프로그램 객체가 없습니다 :) –