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

pass-server-data example: Use API Routes? #8976

Closed
karlhorky opened this issue Oct 6, 2019 · 8 comments · Fixed by #8992
Closed

pass-server-data example: Use API Routes? #8976

karlhorky opened this issue Oct 6, 2019 · 8 comments · Fixed by #8992
Milestone

Comments

@karlhorky
Copy link
Contributor

Examples bug report

Example name

pass-server-data

Describe the bug

So not as much of a bug as a suggestion of a potential improvement:

The data is currently being required and passed to the pages by a custom server.js file that uses Express.

Would the Next.js team be open to migrating this example to use API Routes? Maybe with an implementation along the lines of React Tricks: Exploring Next.js 9 Dynamic Routing & API Routes?

Alternatives

A potential alternative (which would allow retaining the current version of pass-server-data as it is for reference) would be to copy and rename this example to create a new example that did use API Routes.

To Reproduce

Not applicable

Expected behavior

Example uses API Routes

System information

Not Applicable

Additional context

@timneutkens
Copy link
Member

I think the example should be removed, it shows a bunch of bad practices.

@karlhorky
Copy link
Contributor Author

karlhorky commented Oct 6, 2019

Ah, ok! Can you list these other bad practices out?

Maybe these two tasks could be done at the same time? Eg:

  1. Convert the example to use API Routes
  2. Refactor the example to remove bad practices

@timneutkens
Copy link
Member

timneutkens commented Oct 6, 2019

The goal of the example is showing passing data as the querystring which in general you don't want to do, getInitialProps covers fetching data. Furthermore that'd break client-side route transitions as there is no data available when switching pages.

@karlhorky
Copy link
Contributor Author

Ok, so if I was to rework the example in the way described in the blog post, this would be acceptable?

TLDR version:

  • Set up an API route page that requires the data
  • isomorphic-unfetch from that API route in getInitialProps

@timneutkens
Copy link
Member

I guess that might work, but that's already covered here: https://github.com/zeit/next.js/tree/canary/examples/api-routes

@karlhorky
Copy link
Contributor Author

Ok great! Don't need to do anything except remove the pass-server-data example then!

Should I open a PR to do this?

@timneutkens
Copy link
Member

Sure!

@Timer Timer added this to the 9.1.2 milestone Oct 8, 2019
Timer pushed a commit that referenced this issue Oct 8, 2019
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants