// .. appName/src/middleware/ContentTypeHeader.js'use strict';/** * Middleware to send Content-Type header. */module.exports=(req,res,next)=>{res.setHeader('Content-Type','text/html');next();// Run subsequent handler.};// .. appName/src/middleware/SessionCheck.js'use strict';const{RouterError}=require('@lambda-lambda-lambda/router/src/router/Error.js');/** * Middleware to define session state, if exists. */module.exports=async(req,res,next)=>{if(awaitcheckSession()){// Passed down the Router stack.req.plugin('session',true);}else{// Write to CloudWatch, continue..thrownewError('Output to console');}// next() should be omitted};See L³ middleware for more complex use cases.
| Exception type | Description |
|---|---|
throw new RouterError | When called will immediately exit the middleware stack and write the exception to CloudWatch logs. |
throw new Error | When called will write the exception to CloudWatch and run the subsequent handler in middleware stack. |
Promise.reject() | Same as throw new Error with no exception thrown. |