i am using a paid Inufra Ipfs subscription. My code was working till last week but now i am getting cors error
Access to fetch at 'https://ipfs.infura.io/:5001/api/v0/add?stream-channels=true&progress=false' from origin 'https://test-project.trade' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
main.js? attr=8m3phYuNM7Mr_WBs3qsIscqf2TMfcjpDu3YLz5dj9AOOOgFg9wnjM31M91EeMNZH7wm-x4-EZSpyMxJBO5i9_kUhC6BYjYHloOStgpX9GUA: 2671 POST https://ipfs.infura.io/:5001/api/v0/add?stream-channels=true&progress=false net::ERR_FAILED
POST https://ipfs.infura.io/:5001/api/v0/add?stream-channels=true&progress=false net::ERR_FAILED
This is my code.
import { create } from "ipfs-http-client";
export const ipfsPostUrl()=>" https://ipfs.infura.io:5001/api/v0"
export const ipfsAuthPhrase = () =>
"Basic " +
Buffer.from(
config.ipfsAuth.projectId + ":" + config.ipfsAuth.projectSecret
).toString("base64");
const client = create({
url: ipfsPostUrl(),
headers: {
authorization: ipfsAuthPhrase(),
},
});
async function addToIpfs(data){
const { path } = await client.add(JSON.stringify(data));
const cid = new CID(path).toV1();
const cidHex = "0x" + cid.toString("base16").substring(1);
return cidHex;
}