Cross-domain
Cross-domain processing
Cause
The reason for cross-domain is that the front-end address and the backend interface are not the same origin, resulting in ajax not being sent.
Problems caused by non-same-origin
- Cookie, LocalStorage and IndexDB cannot be obtained
- DOM cannot be obtained
- AJAX requests cannot be sent
Same-origin conditions
Protocol, port, and host are the same as the same origin.
On the contrary, as long as one of them is different, it is a different origin.
Solution
Local development cross-domain
Local development generally uses the following 3 methods for processing
- Use vite's proxy for proxy
- Turn on cors in the background
- Use nginx to forward requests
The project comes with the first method. For details, please refer to Server Interaction-Local Development Environment Interface Address Modification
Production environment cross-domain
The production environment generally uses the following 2 methods for processing
- Turn on cors in the background
- Use nginx to forward requests
Turning on cors in the background does not require any changes to the front end
The nginx configuration file can view nginx configuration