Member-only story
Handle CORS in Golang
CORS stands for Cross-Origin Resource Sharing, it’s a mechanism that allow browser to access the content of other websites on their website. It adds security as it do not allow to access the content without the consent of author.
Above image depicts that browser runs a website example.com and requested for content from api.example.com which is a different server but the request got blocked because of CORS Policy due to which the browser will show below mentioned error in their console.
How will the browser identify that the domains are different?
So, here’s the answer to your question, when the domain have,
- Different name (Like https://example.com and https://demo.com)
- Different sub domain (Like https://one.example.com and https://two.example.com)
- Different port (Like https://example.com:8080 and https://example.com:8081)
- Different protocol (Like https://example.com and http://example.com)
To see content of different domain, we need to follow these points.
- Either we need to disable security issue from browser so that it doesn’t check for…