You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to have a middleware, like authorization middleware for example.
How can I use middleware with typescript-rest.
Suppose I have something like this:
app=express();constmyMiddleware=(req,res,next)=>{console.log("I'm in the middle");next();}
@Path("/get")classMyGetController{
@GETgetSomething(){return"Some response";}}app.use('/api',myMiddleware,MyGetController);
How can I do it? How can I augment a class with some middleware in front of it?
How can I use typescript-rest to write middleware, and to compose middleware with controllers?
The text was updated successfully, but these errors were encountered:
Typescript-rest receives an express router as parameter to build the routes for all controllers. You can add any middleware to this router as you do using pure express:
app=express();constmyMiddleware=(req,res,next)=>{console.log("I'm in the middle");next();}
@Path("/get")classMyGetController{
@GETgetSomething(){return"Some response";}}app.use(myMiddleware);Server.buildServices(app);
Or using a router:
constapp=express();constmyMiddleware=(req,res,next)=>{console.log("I'm in the middle");next();}
@Path("/get")classMyGetController{
@GETgetSomething(){return"Some response";}}constapis=express.Router();apis.use(myMiddleware);Server.buildServices(apis);app.use('/apis',apis);
Remember that, as any other middleware for express, the order where you add your middlewares matters.
I'd like to have a middleware, like authorization middleware for example.
How can I use middleware with typescript-rest.
Suppose I have something like this:
How can I do it? How can I augment a class with some middleware in front of it?
How can I use typescript-rest to write middleware, and to compose middleware with controllers?
The text was updated successfully, but these errors were encountered: