Troubleshooting CORS Errors
CORS Errors are common when you're working with APIs but it's very important to handle them effectively due to several security reasons.
DataHub supports "Allowed Origin" functionality which allow users to whitelist their specific domains to be a part of a cross-origin request. You can read more about Allowed Origins functionality HERE
Apart from "Allowed Origins" there are two major ways to not expose your API keys and credentials on the Client-Side.
Use a proxy - One solution for making cross-origin requests is to use a CORS proxy to make it seem as though you're making the request from a location that's allowed.
There are multiple CORS proxies out there that you can use for free. Some examples are as follows -
Use a serverless function - Using a serverless function is another more effective way to handle the CORS errors and proxy our requests and here in this we build our own functions or micro-infrastructure to call a web service and interact using APIs. Azure, AWS & GCP are most popular for running serverless functions.
Sharing some examples of serverless functions built and shared by our community members.
- Azure Function for CORS proxy by Florian Uhde - Check the gist HERE
- AWS Lambda Function for CORS proxy by Austin Woetze - Check the gist HERE
- Template if you want to host your own nginx server - DataHub CORS Development Proxy