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

Where to validate route parameters? #1073

Closed
thangngoc89 opened this issue Feb 10, 2017 · 2 comments
Closed

Where to validate route parameters? #1073

thangngoc89 opened this issue Feb 10, 2017 · 2 comments

Comments

@thangngoc89
Copy link

thangngoc89 commented Feb 10, 2017

So I'm setting up an express server for custom routing.
Suppose I have a route like this /u/:username . After parsing the query param, I need to hit the database, find that username and decide whether I should render a profile page or an 404 page.

I have 2 places to do the validating in mind:

  • At express server

    • Pros: Sending correct HTTP_STATUS code because I can't find a way to send 404 status within the React app
    • Cons: Hit the database server twice because in the client side, I need extra information rather than just a validated username to render the page. Query all of the data in the express server and sending it via ctx would be super complicated. For clarification, I'm using Apollo Client for managing the data.
  • At React app

    • Pros: Hit the database server only one
    • Cons: Improper HTTP_STATUS code, complex error handling. (well, try catch everywhere! OMG)
@nkzawa
Copy link
Contributor

nkzawa commented Feb 10, 2017

#746 (comment) is the way we recommend.
btw you can import the default error page as next/error and use it for rendering from the next release.

@thangngoc89
Copy link
Author

@nkzawa oh nice. Thank you. I was worry for a while before posting the above post. Putting the logic in express mean I have to keep the code in sync manually.

@nkzawa nkzawa closed this as completed Feb 10, 2017
@lock lock bot locked as resolved and limited conversation to collaborators May 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants