How to handle unmatched routes with serverless
Anjan Talatam
Posted on October 21, 2023
Context:
I mistakenly misspelled my login route as /dev/loginn
instead of /dev/login
on Postman, here is the response
{
"currentRoute": "post - /dev/loginn",
"error": "Serverless-offline: route not found.",
"existingRoutes": [...],
"statusCode": 404
}
Problem
The above response has 2 major issues
- Existing routes are getting exposed which shouldn't be (ideally).
- The response is too detailed. We need to keep it simple.
Fix
Add a new Lambda function to handle unmatched/ unconfigured Routes in serverless.yml
#serverless.yml
functions:
unmatchedRoute:
handler: handler.unmatchedRoute
events:
- http:
path: /{proxy+}
method: ANY
// handler.ts
import { Handler } from 'aws-lambda';
export const unmatchedRoute: Handler = async () => {
return {
statusCode: 404,
body: '404 page not found',
};
};
Thanks for reading! Drop a like if you found it helpful ❤️
Cheers! Anjan Talatam
Ignore from here
SEO
- How to handle unconfigured routes with serverless
- How to handle unmatched routes for AWS lambda functions
- How to handle unconfigured routes for AWS lambda functions
- How to handle unconfigured routes for AWS lambda functions with serverless
💖 💪 🙅 🚩
Anjan Talatam
Posted on October 21, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
undefined Using Server-less Functions to Govern and Monitor Cloud-Based Training Experiments
December 23, 2023