Difference between app.all('*') and app.use('/')

后端 未结 7 1923
谎友^
谎友^ 2020-11-29 15:51

Is there a useful difference between app.all(\'*\', ... ) and app.use(\'/\', ...) in Node.JS Express?

7条回答
  •  孤城傲影
    2020-11-29 16:23

    With app.use(), the "mount" path is stripped and is not visible to the middleware function:

    app.use('/static', express.static(__dirname + '/public'));
    

    Mounted middleware functions(express.static) are not invoked unless the req.url contains this prefix (/static), at which point it is stripped when the function is invoked.

    With app.all(), there is no that behavior.

提交回复
热议问题