Skip to content

Proxy to Rest API #281

New issue

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

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

Already on GitHub? # to your account

Closed
maestroh opened this issue Nov 21, 2016 · 2 comments
Closed

Proxy to Rest API #281

maestroh opened this issue Nov 21, 2016 · 2 comments

Comments

@maestroh
Copy link

I have a couple of questions about how server side rendering would work my existing API. How can I run an API under the same port during development? For example, with create-react-app, I would use webpack's proxy configuration. Is there some similar configuration that I can use with next?

Also, in production, how would I run an API and still take advantage of the server side rendering from next?

I'm sure there are simple answers to these questions. I feel like I'm missing some fundamental concepts. Thanks for the help.

@sergiodxa
Copy link
Contributor

sergiodxa commented Nov 21, 2016

There are discussions about how to allow the usage of custom webpack configurations (#40 and #222), that will allow you to use the webpack's proxy configuration.

Meanwhile you can run your API in another port or made use of NGINX as a reverse proxy to do that (I think the different port is the best for development right now because it doesn't require to configure a NGINX).

In production you can use NGINX as a reverse proxy, so the user made a HTTP request to the NGINX server and it will map the requests to the next.js servers (you can have multiple and load-balance them) or if the request are in /api or api.domain.com (for example) you can map them to your API servers.

@rauchg
Copy link
Member

rauchg commented Nov 21, 2016

Great comment by @sergiodxa. We should probably start a wiki page on this as well.

tl;DR: We recommend talking from getInitialProps to something like api.yourdomain.com, or a proxied yourdomain.com/api

Keep server APIs separate. Keep your Next.js app small and scoped to the frontend code.

@rauchg rauchg closed this as completed Nov 21, 2016
@lock lock bot locked as resolved and limited conversation to collaborators May 12, 2018
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants