Skip to content

v5 beta: non-proxy API Gateway REST (v1) resources strip entire path via event.resource, causing 404s #712

@john-gay

Description

@john-gay

Bug Description

In v5, getDefaultStripBasePath was introduced in src/event-sources/utils.js:

function getDefaultStripBasePath(event) {
  const basePathMatched = event?.requestContext?.customDomain?.basePathMatched || '';
  const resource = event?.pathParameters?.proxy ? '' : event.resource;
  return basePathMatched ? `/${basePathMatched}${resource}` : resource;
}

For non-proxy resources (no {proxy+} parameter), event.resource is the full path template defined in API Gateway — e.g. /service/endpoint. When there is no custom domain, stripBasePath is set to /service/endpoint, which is then used as a regex to strip the entire path, leaving an empty string that gets normalised to /.

The path Express receives is / instead of /service/endpoint, causing a 404.

v4 Behaviour

In v4, stripBasePath always defaulted to '', so event.path was passed through untouched:

stripBasePath = '',

Reproduction

API Gateway REST API (v1) with any static (non-proxy) resource, e.g.:

GET /service/endpoint  →  static resource (no {proxy+})

Lambda receives:

{
  "resource": "/service/endpoint",
  "path": "/service/endpoint",
  "pathParameters": null,
  ...
}

v5 computes stripBasePath = '/service/endpoint', strips the full path → Express sees GET / → 404.

Meanwhile, a proxy resource on the same service works fine because pathParameters.proxy is set, which causes resource to be set to '' and the strip is a no-op.

This means in a typical setup where a {proxy+} resource handles most routes alongside a small number of static resources (e.g. a health check), the proxy routes work but the static ones all 404.

Expected Behaviour

Same as v4 — event.resource should not be used as a base path to strip unless a custom domain basePathMatched is explicitly set. The event.resource field reflects the API Gateway resource template, not a mount prefix.

Workaround

For now, downgrading to v4.17.1 restores the previous behaviour.

Environment

  • @codegenie/serverless-express: 5.0.0-beta.1
  • API Gateway: REST API (v1)
  • Resource type: static (non-proxy), no custom domain

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions