(method, path, ...handlers)
| 53 | } |
| 54 | |
| 55 | route(method, path, ...handlers) { |
| 56 | switch (method) { |
| 57 | case 'POST': |
| 58 | case 'GET': |
| 59 | case 'PUT': |
| 60 | case 'DELETE': |
| 61 | break; |
| 62 | default: |
| 63 | throw 'cannot route method: ' + method; |
| 64 | } |
| 65 | |
| 66 | let handler = handlers[0]; |
| 67 | |
| 68 | if (handlers.length > 1) { |
| 69 | handler = function (req) { |
| 70 | return handlers.reduce((promise, handler) => { |
| 71 | return promise.then(() => { |
| 72 | return handler(req); |
| 73 | }); |
| 74 | }, Promise.resolve()); |
| 75 | }; |
| 76 | } |
| 77 | |
| 78 | this.routes.push({ |
| 79 | path: path, |
| 80 | method: method, |
| 81 | handler: handler, |
| 82 | layer: new Layer(path, null, handler), |
| 83 | }); |
| 84 | } |
| 85 | |
| 86 | // Returns an object with: |
| 87 | // handler: the handler that should deal with this request |
no outgoing calls
no test coverage detected