1
0
mirror of https://github.com/spacebarchat/client.git synced 2024-11-25 11:42:30 +01:00

send headers in well known related requests

This commit is contained in:
Puyodead1 2024-06-15 18:39:56 -04:00
parent c31f4153c2
commit f0f67ebdf7
No known key found for this signature in database
GPG Key ID: A4FA4FEC0DD353FC

View File

@ -4,6 +4,12 @@ import { Globals } from "./Globals";
import Logger from "./Logger"; import Logger from "./Logger";
import { RouteSettings } from "./constants"; import { RouteSettings } from "./constants";
const DEFAULT_HEADERS = {
mode: "cors",
"User-Agent": "Spacebar-Client/1.0",
accept: "application/json",
};
export default class REST { export default class REST {
private readonly logger = new Logger("REST"); private readonly logger = new Logger("REST");
private app: AppStore; private app: AppStore;
@ -11,11 +17,7 @@ export default class REST {
constructor(app: AppStore) { constructor(app: AppStore) {
this.app = app; this.app = app;
this.headers = { this.headers = DEFAULT_HEADERS;
mode: "cors",
"User-Agent": "Spacebar-Client/1.0",
accept: "application/json",
};
} }
public setToken(token: string | null) { public setToken(token: string | null) {
@ -34,7 +36,10 @@ export default class REST {
} }
// get endpoints from .well-known // get endpoints from .well-known
const wellKnown = await fetch(`${url.origin}/.well-known/spacebar`) const wellKnown = await fetch(`${url.origin}/.well-known/spacebar`, {
method: "GET",
headers: DEFAULT_HEADERS,
})
.then((x) => x.json()) .then((x) => x.json())
.then((x) => new URL(x.api)); .then((x) => new URL(x.api));
@ -45,6 +50,10 @@ export default class REST {
static async getInstanceDomains(url: URL, knownas: URL): Promise<RouteSettings> { static async getInstanceDomains(url: URL, knownas: URL): Promise<RouteSettings> {
const endpoints = await fetch( const endpoints = await fetch(
`${url.toString()}${url.pathname.includes("api") ? "" : "api"}/policies/instance/domains`, `${url.toString()}${url.pathname.includes("api") ? "" : "api"}/policies/instance/domains`,
{
method: "GET",
headers: DEFAULT_HEADERS,
},
).then((x) => x.json()); ).then((x) => x.json());
return { return {
api: endpoints.apiEndpoint, api: endpoints.apiEndpoint,