Handling CORS Errors
When using the Qube API, CORS errors may occur in a browser environment. CORS (Cross-Origin Resource Sharing) is a browser security feature that restricts resource sharing between different origins (domain, port, or protocol).
Solutions
To prevent CORS errors, adopt one of the following methods:
Using a Proxy Server
Instead of calling the API directly from the client, send requests through a proxy server.
Using a proxy server allows you to bypass CORS restrictions while securely accessing the API.
Example of Proxy Setup
Setting up a proxy with an Express server:
const express = require('express'); const { createProxyMiddleware } = require('http-proxy-middleware'); const app = express(); app.use( '/api', createProxyMiddleware({ target: '<https://www.0xqube.xyz>', changeOrigin: true, }) ); app.listen(3000);
Server-Side Implementation
Call the API directly from the backend server instead of the browser.
This approach avoids CORS errors specific to browser environments.
Last updated
Was this helpful?