So as the title says. I need to call a route from another route.
I have used run-middleware npm module but after using it Morgan showing odd outputs, like showing two http request but both are same. Also accessing invalid route not going to catch all route. Instead its throwing error. Here is a log.
data: app/server.js:29146 - ======================================
data: app/server.js:29146 - 200
data: app/server.js:29146 - <!DOCTYPE html>
data: app/server.js:29146 - <html lang="en">
data: app/server.js:29146 - <head>
data: app/server.js:29146 - <meta charset="utf-8">
data: app/server.js:29146 - <title>Error</title>
data: app/server.js:29146 - </head>
data: app/server.js:29146 - <body>
data: app/server.js:29146 - <pre>Cannot POST /api/v1/auth/authenticate</pre>
data: app/server.js:29146 - </body>
data: app/server.js:29146 - </html>
data: app/server.js:29146 - ======================================
data: app/server.js:29146 - POST /api/v1/auth/authenticate - - ms - -
data: app/server.js:29146 - POST /api/v1/auth/authenticate 200 474.491 ms - 268
I used the below code where /asd route is invalid
req.runMiddleware('/asd',{method:'post'},function(code,data){
console.log('======================================');
console.log(code);
console.log(data);
console.log('======================================');
});
Is there any other library for this purpose?
or anyone can help me to create my own? I know how to make a middleware & how to invoke the middleware chain of express, I just want to know which fields of req objects need to be changed and restore.