1

I was developping a app with React app. In developing env i was using proxy but I'm deploying the app and I saw that proxy didn't work in.

I read about http-proxy-middleware. It can be a solution or it don't works too?

Any way to do this without config the server with redirects to other port?

I need to continue fetching to my API server.

2 Answers 2

1

The best way what I found without configure server and NGINX is follow this steps:

  1. Build front
  2. Move folder into a backend server.
  3. Put that code after routes:

    if (process.env.NODE_ENV === 'production') {
       app.use(express.static(`${__dirname}/yourFrontFolder/build`));
       app.get('*', (req, res) => {
        res.sendFile(`${__dirname}/yourFrontFolder/build/index.html`);
       })
       ...
    

    And build your backend code and access to your backend port like frontend.

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

Comments

0

You don't usually need a proxy in your React app when it is deployed. To deploy, you usually run npm run build, which creates a build directory containing all the compiled JavaScript and HTML files you need for the deployment. These are then served by a web server, such as NGINX or by your backend application.

4 Comments

I used proxy for petitions to an API
After deployment you would use a web server as a proxy to your API, that can also server your react app. With NGINX, for instance, you would have it serve your react app and have a special route as a proxy to your API, using the proxy_pass directive. See this link for more information: docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy
As i said I don't wanna configurate NGINX and server. Look at my answer!
You said you didn't want to configure your server with redirects, which my solution doesn't. Could you please state your question more precisely to allow people to help you more accurately in future?

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.