0

I am looking to serve out some data from some json and csv files to my front end, which is built on create-react-app.

My idea is to have them both listen at different ports (3000 for React, 3001 for express backend) and then make API calls to 3001 to get whatever data I need through ajax.

How can this work in production? For instance with Heroku, how would I go about deploying this since it's listening at 2 different ports?

What unforeseen issues will this have/ is there a better method?

To add some more info: All my backend is doing is parsing some csv and json and serving it out in formatted and edited json.

3
  • The answer to this question is already available with a simple google search, something the "how do I ask a good question" policy article quite clearly tells you to do before posting. I googled for "create-react-app heroku" and the very first hit was github.com/mars/create-react-app-buildpack which covers the answer in fine detail. Commented Jul 15, 2017 at 18:57
  • @Mike'Pomax'Kamermans It seems you have misread my question Commented Jul 15, 2017 at 18:59
  • @mohammed I'm pretty sure you responded before you had time to read that entire page, so: read that entire page. If those instructions are not sufficient for you then you can now update your question with "I read through X but the instructions don't cover how I ... ". You are as much responsible in helping answering this question as we are, so you're on the hook to be as detailed in your question as can be. React is not itself a server, only Express is, so even if react runs a dev hot loader through webpack or the like on an alternative port, that is irrelevant for deployment, disabled by env. Commented Jul 15, 2017 at 19:02

1 Answer 1

1

If you use Heroku, it is recommended to use two dynos separately. One for serving static files and react, and the other for API server.

Or you can use PM2 to do the same things in one dyno, by using fork mode of it.

In both case, as two servers don't share the same port, you will have some problems using sessions, and troubles to make API requests. I think it can be solved by using token based authorization like jwt or using separate session storage like redis

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.