Я новичок в Thingsboard, и у меня есть сервер Tingsboard. Я пытаюсь получить доступ к API REST вещей и в результате ошибки CORS, потому что запрос OPTIONS возвращает 401.
Это мой thingsboard.yml, и по умолчанию кажется, что CORS поддерживается с '*'
spring.mvc.cors:
mappings:
# Intercept path
"/api/auth/**":
#Comma-separated list of origins to allow. '*' allows all origins. When not set,CORS support is disabled.
allowed-origins: "*"
#Comma-separated list of methods to allow. '*' allows all methods.
allowed-methods: "POST,GET,OPTIONS"
#Comma-separated list of headers to allow in a request. '*' allows all headers.
allowed-headers: "*"
#How long, in seconds, the response from a pre-flight request can be cached by clients.
max-age: "1800"
#Set whether credentials are supported. When not set, credentials are not supported.
allow-credentials: "true"
Я проверил этот вопрос Thingsboard Нет заголовка «Access-Control-Allow-Origin» на запрошенном ресурсе. angularjs но мне не ясно, как отключить аутентификацию для OPTIONS, как прокомментировано. Я попробовал код в ссылке, но получил 401.
var url = "http://THINGSBOARDURL:PORT/api/customer/d8f7b410-5480-11e9-bc30-bd0cca1006d3/assets?limit=10";
var xhr = createCORSRequest('GET', url);
if (!xhr) {
alert('CORS not supported');
return;
}
// Response handlers.
xhr.onload = function() {
var text = xhr.responseText;
console.log(text);
};
xhr.onerror = function() {
alert('Woops, there was an error making the request.');
};
xhr.setRequestHeader("Accept", "application/json")
xhr.setRequestHeader("X-Authorization","Bearer JWTTOKEN")
xhr.send();
Доступ к XMLHttpRequest по адресу http://URL:PORT/api/customer/d8f7b410-5480-11e9-bc30-bd0cca1006d3/assets?limit=10' от источника 'http://localhost:8100' заблокирован политикой CORS: Ответ на предпечатный запрос не проходит проверку контроля доступа: Нет' Access-Control-Allow- Заголовок источника присутствует на запрашиваемом ресурсе.
Пожалуйста, помогите