Catch all route EXCEPT for /login

前端 未结 4 1199
耶瑟儿~
耶瑟儿~ 2020-12-13 05:16

I am currently writing an API which will require a user to pass an authentication token in the header of each request. Now I know I can create a catchall route say

4条回答
  •  旧时难觅i
    2020-12-13 06:07

    I'm not sure what you want to happen when a user accesses /login or /, but you can create separate routes for those; if you declare them before the catch-all, they get first dibs at handling the incoming requests:

    app.get('/login', function(req, res) {
      ...
    });
    
    app.get('/', function(req, res) {
      ...
    });
    
    app.get('*', function(req, res) {
      ...
    });
    

提交回复
热议问题