When developing the debugging interface in the front-end, you will encounter the problem of cross-domain request. The traditional way is to use Nginx reverse proxy to solve cross-domain. For example, all interfaces are in a.com
the domain of , and all requests can be proxied to a.com
the domain of .
When developing with frameworks and Webpack, reverse proxy can also be implemented through plugins. For example, when using Angular, you can proxy.config.json
perform cross-domain settings through .
However, if the developed test environment requires login authentication, the request needs to carry cookie information. Can be set when sending a request via Fetch credentials: 'include'
. In Angular, it's settings withCredentials: true
. But there are still cross-domain issues. For example, the local server is localhost:XXXX
, and the logged-in cookie information is under a.com
the domain of . So it still can't solve the cross-domain problem. I don't know if I haven't found a more scientific method.
In order to solve this problem, a relatively conservative approach was finally adopted, which can be used to manually modheader
add . Although the problem is solved, when switching pages, the plug-in switch needs to be set repeatedly, because the cookies of each page are different. No better solution has been found for the time being.