The “Access-Control-Allow-Origin” header needs to be set by your server, not your client.
You’re using the POST method on your server but GET on the client.
For problem #1, you need to set that header from your server. It looks like you’re using Koa or Express. Use a package like this one: https://expressjs.com/en/resources/middleware/cors.html. It’ll configuration the CORS headers based on what you need. Using “*” is wide open… if you can, I’d recommend using the domain of your clients.
For problem #2, make sure the method in your fetch call matches the method you’ve set on your route.
async function cookieTest() {
fetch(${url}api/auth/cookieTest, {
method: “get”,
headers: headers,
})
.then((response) => response.json())
.then((data) => console.log(data))
.catch((err) => console.log(err));
}
if useful marks as like and accept solution
@RyanMacdonald could you please help me. How to get shop url in node and react app in backend or serversde. I want shop url in ndex.js or middlewre? I am calling this api but failed to get shop url here