Проблема с Cors и получением информации в react
У меня проблема с CORS и фетчем с REACT.JS.
Вот мой код:
let componentMounted = true;
useEffect(() => {
const getCars = async () => {
const response = await fetch('http://127.0.0.1:8000/dealership/cars/?format=json', {mode: 'no-cors'});
if(componentMounted){
setData(await response.clone().json());
setFilter(await response.json());
}
return () => {
componentMounted = false;
}
}
getCars();
}, []);
В консоли Chrome у меня такая ошибка:
Uncaught (in promise) SyntaxError: Unexpected end of input (at Cars.js:17:1) at getCars (Cars.js:17:1)
А это:
Cross-Origin Read Blocking (CORB) blocked cross-origin response http://127.0.0.1:8000/dealership/cars/?format=json with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.
В бэкенде у меня Django и я импортировал Cors-headers следующим образом:
CORS_ALLOWED_ORIGINS = [
'http://localhost:3000',
]