I’m new to web dev and I’m facing a error:
“URLEXAMPLE/:1 Access to XMLHttpRequest at ‘https://DIFFERENTURLEXAMPLE’ from origin ‘https://URLEXAMPLE’ 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.”
However I searched and no solution for this error. I would like to know how could I get a more precise info about the error.
My node back end server cors config(I’ve tried already modify the origin to the DIFFERENTURLEXAMPLE with no success):
app.use(
cors({
origin: '*',
methods: ['GET', 'PATCH', 'POST', 'DELETE', 'PUT'],
credentials: true,
}),
);
app.use(helmet());
My axios frond end config:
import axios from 'axios';
const axiosInstance = axios.create({
baseURL: import.meta.env.VITE_BACK_END_URL,
withCredentials: true
});
axiosInstance.interceptors.response.use(
(response) => response,
(error) =>
Promise.reject(
(error.response && error.response.data) || 'Something went wrong',
),
);
export default axiosInstance;
May you have any suggestion about why this error is happening?