Ask Your Question
0

How can CORS policy be resolved when there is a dockerized react+django application and access to 'http://localhost:8000' from 'http://localhost' via XMLHttpRequest is blocked?

asked 2021-11-24 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-09-20 03:00:00 +0000

david gravatar image

There are several ways to resolve CORS policy issues when working with a dockerized react+django application:

  1. Use a proxy server: Set up a proxy server, such as NGINX, to act as a middleman between the React app and the Django backend. The proxy server will handle the CORS headers and allow the React app to access the Django backend.

  2. Use Django CORS headers: Install the Django CORS headers library and configure it to allow cross-origin requests. This will add the necessary headers to the responses from the Django backend and allow the React app to access it.

  3. Use a browser extension: Install a browser extension, such as CORS Everywhere, that will modify the CORS headers in the browser and allow cross-origin requests to be made.

  4. Use a development server with CORS disabled: When running the application in development mode, use a development server that has CORS disabled. This will allow the React app to access the Django backend without any issues. However, this should not be done in production mode as it can pose a security risk.

Ultimately, the solution will depend on the specific requirements and constraints of the project. It's important to carefully consider the security implications and choose the option that best meets the project's needs.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-11-24 11:00:00 +0000

Seen: 11 times

Last updated: Sep 20 '22