Fetch
Use these code examples for bypassing CORS errors in Fetch requests with Corsfix CORS proxy. They use the Corsfix SDK, a drop-in wrapper around fetch. Load it with a script tag:
<script src="https://unpkg.com/corsfix"></script>Or install it from npm:
npm install corsfiximport corsfix from "corsfix";GET Request
Section titled “GET Request”corsfix.fetch("https://api.example.com/data");Cached Response
Section titled “Cached Response”corsfix.fetch("https://api.example.com/data", { corsfix: { cache: "15m" },});POST Request
Section titled “POST Request”corsfix.fetch("https://api.example.com/data", { method: "POST", body: JSON.stringify({ data: "mydata", }),});Using Secrets
Section titled “Using Secrets”corsfix.fetch("https://api.example.com/data?key={{SECRET_KEY}}", { method: "POST", headers: { Authorization: "Bearer {{SECRET_TOKEN}}", }, body: JSON.stringify({ data: "mydata", }),});Header Override
Section titled “Header Override”corsfix.fetch("https://api.example.com/data", { corsfix: { headers: { "User-Agent": "MyAgent/1.0", }, },});