Skip to content

Handle async pathRewrite function #374

@WestonThayer

Description

@WestonThayer

Is this a feature request?

Yes. I would like a pathRewrite function that returns a Promise to be handled. Currently it can only return a string.

My use case is: when a request for /api/foo?auth_token=xxx arrives, I need to:

  1. Grab auth_token and check its validity. This is an async operation
  2. If it is valid, use the token to look up some additional information that token has permission to access in a database (also an async operation)
  3. Assuming all goes well, return a rewritten path, like /other-api/bar?db-field-1=abc&db-field-2=abc. If it did not go well, the path will be rewritten to /other-api/404

Similar to #318, but this covers the case where more than just the response headers/status needs to be modified.

I have this working and tested in a local fork, please let me know if you would accept a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions