question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: How to proxy requests in production?

See original GitHub issue

I feel like an idiot…

I have create-react-app and a Rails 5 API. All requests should hit the rails server, and I was able to use the proxy feature in package.json, which is awesome!

"proxy": "http://localhost:3001"

But how do I do this in production? In production my rails server can’t live at the same domain as my create-react-app right, unless I am missing something?

Thanks for your help.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
Timercommented, May 27, 2017

@patwalls hi! You need to set this up yourself; most likely on the rails side. You can make rails serve the static assets so they’re on the same domain, or you can prefix all of your api calls with the API-server URL and control it via an env var (/ in dev, http://api.example.com/ in production).

Even if rails only serves the index.html, you can configure the production build to reference a CDN/different url. Checkout the PUBLIC_URL env var.

2reactions
mjsisleycommented, Oct 31, 2017

Make I an environment variable something like process.env.REACT_APP_API_DOMAIN. Make sure it is set when you build (Netfliy let’s you set env vars, of building locally can use cross-env or dotenv

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create-React-App Proxy in Production Build - Stack Overflow
Please be sure to answer the question. Provide details and share your research! ... Asking for help, clarification, or responding to other answers ......
Read more >
Why you should use a proxy server with Create React App
Learn why and how to implement a proxy server with Create React ... I recommend following these guides to implement proxies in production:....
Read more >
React — How To Proxy To Backend Server - Medium
We need to have a backend server and UI running on different ports. The proxy entry should be added to the package. json...
Read more >
API proxy configuration reference | Apigee Edge
Specifies the endpoint path of an API proxy to use as a target for requests. The target proxy must be in the same...
Read more >
Configure a Proxy in React - James Q Quick
easier to run your frontend React app separate from your backend. For this to work, though, you'll need to make cross-origin requests since...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found