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

Encoded version of path variables should be used #4

Open
joshua-econify opened this issue Dec 27, 2019 · 0 comments · May be fixed by #5
Open

Encoded version of path variables should be used #4

joshua-econify opened this issue Dec 27, 2019 · 0 comments · May be fixed by #5

Comments

@joshua-econify
Copy link
Contributor

joshua-econify commented Dec 27, 2019

Module currently uses decoded path variables via req params:

asExpressRoute() {
    return async (req: express.Request, res: express.Response) => {
      const { query, params, body } = req;
      
      const parsedQueryVariables = this.typecastVariables(query);
      const parsedPathVariables = this.typecastVariables(params);
...

https://github.com/Econify/graphql-rest-router/blob/master/Route.ts#L290

req.params implicitly decodes each part of the path into a corresponding path variable.

If one of the path variables is used as a slug, then that slug would need to be stored decoded in the database in order to be looked up. Storing a slug as a decoded path means the slug is no longer a valid part of a URL. If the slug is used for embedded URLs this means it will have to be encoded every time.

Since a slug is part of URL, believe it is a reasonable expectation of consumers of the library to store slugs in a valid encoded form.

To my knowledge, because const { params } = req; implicitly decodes each value in the object, it is currently impossible to look up an encoded slug.

Thoughts/ideas/gotchas?

@joshua-econify joshua-econify linked a pull request Dec 27, 2019 that will close this issue
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 a pull request may close this issue.

1 participant