Я пытаюсь сделать топор ios получить запрос, но получаю ошибочную политику. Я новичок в топоре ios, вот что я попробовал:
useEffect(() => {
let url =
'http://18.189.49.66:3000/api/calculate/' +
props.type +
'/' +
height +
'/' +
width;
var config = {
headers: { 'Access-Control-Allow-Origin': '*' }
};
axios.get(url, config).then(_result => {
console.log('Duomenys: ' + JSON.stringify(_result));
});
}, [length, width, height]);
В моем app.js
на node.js express у меня есть такие строки:
var cors = require('cors');
app.use(cors());
И вот ошибка:
Access to XMLHttpRequest at 'http://18.189.49.66:3000/api/calculate/LF/80/200'
from origin 'http://localhost:3000' has been blocked by CORS policy:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
xhr.js:172 GET http://18.189.49.66:3000/api/calculate/LF/80/200 net::ERR_FAILED dispatchXhrRequest
@ xhr.js:172 xhrAdapter
@ xhr.js:11 dispatchRequest
@ dispatchRequest.js:59 Promise.then (async) request
@ Axios.js:53 Axios.<computed>
@ Axios.js:68 wrap
@ bind.js:9 (anonymous)
@ Calculator.js:113 commitHookEffectList
@ react-dom.development.js:22030 commitPassiveHookEffects
@ react-dom.development.js:22064 callCallback
@ react-dom.development.js:336 invokeGuardedCallbackDev
@ react-dom.development.js:385 invokeGuardedCallback
@ react-dom.development.js:440 flushPassiveEffectsImpl
@ react-dom.development.js:25392 unstable_runWithPriority
@ scheduler.development.js:697 runWithPriority$2
@ react-dom.development.js:12149 flushPassiveEffects
@ react-dom.development.js:25361 flushDiscreteUpdates
@ react-dom.development.js:24359 finishEventHandler
@ react-dom.development.js:1384 batchedEventUpdates
@ react-dom.development.js:1418 dispatchEventForPluginEventSystem
@ react-dom.development.js:5894 attemptToDispatchEvent
@ react-dom.development.js:6010 dispatchEvent
@ react-dom.development.js:5914 ListPicker._handleMouseUp createError.js:16
Uncaught (in promise) Error: Network Error
at createError (createError.js:16)
at XMLHttpRequest.handleError (xhr.js:81)
Мой бэкэнд:
... var cors = require ('cors'); ...
app.use(cors());
...
Как мне отредактировать мой запрос?