Usage of pathRewrite in Vue cross-domain configuration proxyTable

Cross-domain issues: Reference
Usually the most frequently asked questions are about cross-domain issues. In fact, cross-domain issues are really not a difficult problem to solve. Here I will briefly summarize several cross-domain solutions I recommend.

The way I recommend the most and the way I use it in my work is: cors is called Cross Origin Resource Sharing (cross-domain resource sharing). This solution has no workload for the front end, and there is no difference in writing the normal sending request. The workload is basically on the back end. For each request, the browser must first send a pre-request in the form of an OPTIONS request (not all requests will send options, expand and introduce me), and learn the HTTP method supported by the server for cross-origin requests through the pre-check request. After confirming that the server allows the cross-origin request, send the real request with the actual HTTP request method. The reason for the recommendation is: as long as it is configured for the first time, no matter how many interfaces and projects there are, it can be reused, and the cross-domain problem is solved once and for all, and it can be used conveniently in both the development environment and the official environment. Detailed MDN documentation

But there are always backends who find it troublesome and don’t want to do this, so there are solutions for pure frontends.

In the dev development mode, it is also very convenient to use the proxy of webpack. You can use it by referring to the document. This method is used by some personal projects of the landlord. But this method cannot be used in a production environment. In the production environment, nginx needs to be used as a reverse proxy. The principle of both proxy and nginx is the same, by building a transit server to forward requests to avoid cross-domain problems.

development environment Production Environment
cors core
proxy nginx

Here I only recommend these two cross-domain methods. There are many other cross-domain methods but they are not recommended. These two methods are really mainstream.

Practical Application: Reference
insert image description here

Guess you like

Origin blog.csdn.net/qq_34663267/article/details/125180695