About the problem of Angular cross-domain request carrying cookies

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.comthe domain of , and all requests can be proxied to a.comthe 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.jsonperform 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.comthe 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 modheaderadd . 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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325374503&siteId=291194637