mirror of
https://github.com/owncast/owncast.git
synced 2024-11-21 20:28:15 +03:00
Support API calls without auth and without cors
This commit is contained in:
parent
c4351a53bf
commit
3eb7b8b84a
2 changed files with 11 additions and 10 deletions
|
@ -1,3 +1 @@
|
||||||
NEXT_PUBLIC_ADMIN_USERNAME=admin
|
|
||||||
NEXT_PUBLIC_ADMIN_STREAMKEY=abc123
|
|
||||||
NEXT_PUBLIC_API_HOST=/
|
NEXT_PUBLIC_API_HOST=/
|
|
@ -37,16 +37,19 @@ export const LOGS_WARN = `${API_LOCATION}logs/warnings`;
|
||||||
const GITHUB_RELEASE_URL = "https://api.github.com/repos/owncast/owncast/releases/latest";
|
const GITHUB_RELEASE_URL = "https://api.github.com/repos/owncast/owncast/releases/latest";
|
||||||
|
|
||||||
export async function fetchData(url) {
|
export async function fetchData(url) {
|
||||||
|
let options: RequestInit = {};
|
||||||
|
|
||||||
|
if (ADMIN_USERNAME && ADMIN_STREAMKEY) {
|
||||||
const encoded = btoa(`${ADMIN_USERNAME}:${ADMIN_STREAMKEY}`);
|
const encoded = btoa(`${ADMIN_USERNAME}:${ADMIN_STREAMKEY}`);
|
||||||
|
options.headers = {
|
||||||
|
'Authorization': `Basic ${encoded}`
|
||||||
|
}
|
||||||
|
options.mode = 'cors';
|
||||||
|
options.credentials = 'include'
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, options);
|
||||||
headers: {
|
|
||||||
'Authorization': `Basic ${encoded}`,
|
|
||||||
},
|
|
||||||
mode: 'cors',
|
|
||||||
credentials: 'include',
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const message = `An error has occured: ${response.status}`;
|
const message = `An error has occured: ${response.status}`;
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
|
|
Loading…
Reference in a new issue