Home  >  Article  >  Web Front-end  >  What to do if react cannot be accessed during startup

What to do if react cannot be accessed during startup

藏色散人
藏色散人Original
2023-01-04 10:33:212512browse

Solutions to the inaccessibility of react startup: 1. Install "http-proxy-middleware"; 2. Find "setupProxy.js" and delete it directly; 3. Create a new project and restart the project.

What to do if react cannot be accessed during startup

The operating environment of this tutorial: Windows 10 system, react18.0.0 version, Dell G3 computer.

What should I do if the react startup cannot be accessed?

The react project startup shows that the local connection has been refused

It’s a very strange problem. I could use it normally the day before, and then opened the computer to start the project the next day A problem occurred.

The solution for react project startup showing that the local connection has been refused was not found on Baidu

You can connect normally by going back to the previous version through the git version

There was really nothing I could do at the beginning, so I continued writing from the previous version.

As a result, there was a version conflict. After I solved it manually, I started the project again.

The local connection was refused again...

I was so angry and numb at the time

I couldn’t find a way to do it anymore, so I had to use stupid methods

to create a new project and make sure that the new project could be started.

Moved the original project files one by one

Finally I successfully found the culprit

What to do if react cannot be accessed during startup

This thing is used as a proxy Yes, just delete this thing and you can start it normally, but not vice versa

The problem lies here

There are several ways to write this because of version issues

Put it here The version I can use normally

const { createProxyMiddleware } = require('http-proxy-middleware')
 
module.exports = function (app) {
 
  app.use(createProxyMiddleware('/api', {
 
    target: 'http://106.14.82.240:3000',
 
    secure: false,
 
    changeOrigin: true,
 
    pathRewrite: {
 
      "^/api": "/api"
 
    }
 
  }))
 
}

Also remember to install http-proxy-middleware

Recommended learning: "react video tutorial"

The above is the detailed content of What to do if react cannot be accessed during startup. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn