Как перенести все данные с Postman в axios для создания запроса?
Хочу сделать запрос с помощью axios. В Постмане все работает, но на axios есть проблемы с cors и авторизацией.
Пример кода -
const data = {
query: {
bool: {
must: [{ match: { domain: '' } }, { match: { full_text_ua: query } }],
},
},
};
const username = 'elastic';
const password = 'search';
const basicAuth = Buffer.from(`${username}:${password}`, 'utf8').toString('base64');
return request.post(
'https://new.sourcex.net:2443/api/console/proxy?path=%2Fmain_index%2F_search&method=GET',
{
data: JSON.stringify(data),
},
{
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,PATCH,OPTIONS',
Authorization: `Basic ${basicAuth}`,
'kbn-xsrf': 'reporting',
},
}
);
};
Примеры ошибок -
Access to XMLHttpRequest at 'https://new.sourcex.net:2443/api/console/proxy?path=%2Fmain_index%2F_search&method=GET' 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.
xhr.js:178 POST https://new.sourcex.net:2443/api/console/proxy?path=%2Fmain_index%2F_search&method=GET net::ERR_FAILED
Стоит также сказать, что запрос идет на ссылку с Elastic Search.