So I am getting this error when trying to make an axios call to my api on another localhost. How can I fix this. I am using Nextjs, ts and axios.
Here is the function (it is poorly written, just for testing in the meantime):
const GetPartners = (e: { preventDefault: () => void; }) => {
e.preventDefault();
let token: string =
"//This is normally correct just changed for question";
axios
.get(
"http://localhost:7071/api/Partners",
{
headers: {
Authorization: "Bearer " + token,
},
}
)
.then(res => console.log(res.data));
}
return (
<div className={styles.container}>
<button onClick={GetPartners}>Get Partners</button>
</div>
);
};
export default Home;
and the error:
Access to XMLHttpRequest at 'http://localhost:7071/api/Partners' from origin 'http://localhost:3000' 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.