dougmoscrop / serverless-http

Use your existing middleware framework (e.g. Express, Koa) in AWS Lambda 🎉
Other
1.72k stars 166 forks source link

Configuration option to strip basePath/stage from event.path #68

Closed ceefour closed 5 years ago

ceefour commented 5 years ago

The current assumption is that either (for AWS API Gateway):

  1. the app is deployed to / basePath; or
  2. the (express) app will handle both local development (/ path prefix) and remote development paths (/basePath/stage path prefix)

Meaning that by default, an app that works locally or with / basePath will get errors like:

Cannot GET /geo/v1/geoPlaces/findTopCityLikeByPopulation

When deployed to geo:* basePath.

This is similar issue to https://github.com/awslabs/aws-serverless-express/issues/86 and https://github.com/claudiajs/claudia/issues/170

Currently I use a workaround like this:

module.exports.handler = async (event, context) => {
  // FIXME: Ugly workaround for https://github.com/awslabs/aws-serverless-express/issues/86 and https://github.com/claudiajs/claudia/issues/170
  event.path = event.path.replace(/^\/geo\/v[^/]+/, '')
  return await handler(event, context)
}

It'd be great if this use case can be explicitly supported by a configuration option, or at least, mentioned in the README.md / documentation for AWS provider.