Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make event.pathParameter a full object #968

Merged
merged 3 commits into from
Dec 16, 2022
Merged

make event.pathParameter a full object #968

merged 3 commits into from
Dec 16, 2022

Conversation

tulsidas
Copy link
Contributor

when creating pathParameters in a dynamic route, the resulting object is a null prototype object which causes problems for libraries that try to inspect pathParameters using prototype methods

this patch creates pathParameters as a "full fledged" object

when creating pathParameters in a dynamic route, the resulting object is a `null prototype` object which causes problems for libraries that try to inspect pathParameters using prototype methods

this patch creates pathParameters as a "full fledged" object
@willfarrell
Copy link
Member

Can you add a test please to show when this happens and returns the new empty object you're proposing.

@tulsidas
Copy link
Contributor Author

@willfarrell added !

@willfarrell willfarrell merged commit 8ced566 into middyjs:main Dec 16, 2022
@willfarrell
Copy link
Member

Thanks! That's what I thought the use case was for, but wanted to make sure. Also this test will catch any regressions.

@tulsidas
Copy link
Contributor Author

Hi @willfarrell , one issue I'm having related to this is that the event may already have some pathParameters and the code is not updating them with the dynamic parts of the route, for example:

lambda is defined in serverless.yml as follows:

functions:
  index:
    handler: dist/index.handler
    events:
      - http:
          path: /{proxy+}
          method: any

And I have defined a dynamic route /v1/users/{id}

Then a request comes to /v1/users/123

But the AWS event already has pathParameters set, like:

{
  "resource": "/{proxy+}",
  "path": "/v1/users/123",
  "httpMethod": "GET",
  "pathParameters": {
    "proxy": "v1/users/123"
  },
  ...

So this line won't set the required {id: 123} value in the pathParameters hence the lambda will fail

Should this be fixed in http-router? (I can create a new PR for it) or I am doing something wrong with my configuration?

Thanks

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

Successfully merging this pull request may close these issues.

2 participants