Skip to content

Conversation

@thorhj
Copy link

@thorhj thorhj commented Jun 20, 2023

On my team we have an API Gateway with a stage that we want to include in the URL passed to fastify. E.g. we have the stage stage with a resource my-resource, we would have this route in fastify:

app.get("/stage/my-resource", ...);

Currently the "stage" part is stripped from the URL:

    let url = event.path || event.rawPath || '/' // seen rawPath for HTTP-API
    // NOTE: if used directly via API Gateway domain and /stage
    if (event.requestContext && event.requestContext.stage && event.requestContext.resourcePath &&
        (url).indexOf(`/${event.requestContext.stage}/`) === 0 &&
        event.requestContext.resourcePath.indexOf(`/${event.requestContext.stage}/`) !== 0) {
      url = url.substring(event.requestContext.stage.length + 1)
    }

This PR adds a new option called retainStage that will make sure to retain the stage part of the URL.

This extends the public API! I have documented the change in README.md and updated the TS definition. The change is non-breaking.

Checklist

npm run test

...
Suites:   ​3 passed​, ​3 of 3 completed​
Asserts:  ​​​222 passed​, ​of 222​
npm run performance

aws-serverless-express x 10,951 ops/sec ±11.14% (75 runs sampled)
(node:31068) [FSTDEP011] FastifyDeprecation: Variadic listen method is deprecated. Please use ".listen(optionsObject)" instead. The variadic signature will be removed in `fastify@5`.
(Use `node --trace-warnings ...` to show where the warning was created)
aws-serverless-fastify x 15,076 ops/sec ±2.88% (89 runs sampled)
serverless-http x 32,611 ops/sec ±6.82% (83 runs sampled)
aws-lambda-fastify x 43,800 ops/sec ±2.82% (81 runs sampled)
aws-lambda-fastify (serializeLambdaArguments : true) x 44,551 ops/sec ±1.99% (85 runs sampled)
aws-lambda-fastify (decorateRequest : false) x 43,636 ops/sec ±3.34% (81 runs sampled)
Fastest is aws-lambda-fastify (serializeLambdaArguments : true),aws-lambda-fastify,aws-lambda-fastify (decorateRequest : false)

@adrai adrai merged commit 4ccb68b into fastify:master Jun 20, 2023
@adrai
Copy link
Member

adrai commented Jun 20, 2023

thank you for your contribution... it's included in v3.3.0

@thorhj
Copy link
Author

thorhj commented Jun 20, 2023

Cool, thanks @adrai
When will v3.3.0 be released you think?

@adrai
Copy link
Member

adrai commented Jun 20, 2023

already published

@thorhj
Copy link
Author

thorhj commented Jun 20, 2023

Ah yes, was looking at the Github Releases. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants