I am about to deploy a react app. I have an API for my react app. On a react development server, it serves react on port 3000, and my API is on port 4000.
I see two ways of going about this.
One way is to use CORS in development. If we go this route, we'll need to also use CORS in production. We'll have an ENV file which tells the react app which host/port it should make requests to. Our CI pipeline will have 2 docker containers, 2 repos. When we deploy a frontend or a backend change, we'll be able to restart both servers independently. We'll have 1 docker running on mysite.com and the api running on api.mysite.com.
Another approach is to use the proxy in package.json and forward all requests to our backend. i.e. instead of having to make requests to localhost:4000/sign-in we just make requests to /sign-in. With this approach, I think it makes a lot of sense to use a monorepo. We would have
app
api/
my-api
ui/
my-react-app
My api would be mostly RESTful routes, but would have a catch all for all non-api routes that would serve an HTML file which would serve the javascript. The CI pipeline would build and minizmie and push the JS to S3 and give it a name such as {SHA1}.min.js and our API's index.html file would have
<script src=`{SHA1}.min.js`></script>
I can't seem to make up my mind as to the better approach. Will it be simpler to be able to independently deploy the frontend vs backend? Is it unnecessary to have a docker that only serves a single html file ? Which path should we take ?