diff --git a/src/providers/DynmapMapProvider.ts b/src/providers/DynmapMapProvider.ts index bdad4e9..d54fc04 100644 --- a/src/providers/DynmapMapProvider.ts +++ b/src/providers/DynmapMapProvider.ts @@ -591,7 +591,7 @@ export default class DynmapMapProvider extends MapProvider { this.markersAbort = new AbortController(); - const response = await DynmapMapProvider.fetchJSON(url, this.markersAbort.signal); + const response = await DynmapMapProvider.getJSON(url, this.markersAbort.signal); const sets: Map = new Map(); response.sets = response.sets || {}; @@ -626,7 +626,7 @@ export default class DynmapMapProvider extends MapProvider { this.configurationAbort = new AbortController(); - const response = await DynmapMapProvider.fetchJSON(this.config.dynmap!.configuration, this.configurationAbort.signal); + const response = await DynmapMapProvider.getJSON(this.config.dynmap!.configuration, this.configurationAbort.signal); if (response.error === 'login-required') { throw new Error("Login required"); @@ -664,7 +664,7 @@ export default class DynmapMapProvider extends MapProvider { this.updateAbort = new AbortController(); - const response = await DynmapMapProvider.fetchJSON(url, this.updateAbort.signal); + const response = await DynmapMapProvider.getJSON(url, this.updateAbort.signal); const players: Set = new Set(), updates = this.buildUpdates(response.updates || []), worldState = { @@ -734,6 +734,7 @@ export default class DynmapMapProvider extends MapProvider { return fetch(this.config.dynmap!.sendmessage, { method: 'POST', + credentials: 'include', body: JSON.stringify({ name: null, message: message, diff --git a/src/providers/MapProvider.ts b/src/providers/MapProvider.ts index 1ed9c4a..63709b8 100644 --- a/src/providers/MapProvider.ts +++ b/src/providers/MapProvider.ts @@ -58,11 +58,11 @@ export default abstract class MapProvider implements LiveAtlasMapProvider { this.currentWorldUnwatch(); } - protected static async fetchJSON(url: string, signal: AbortSignal) { + protected static async fetchJSON(url: string, options: any) { let response, json; try { - response = await fetch(url, {signal}); + response = await fetch(url, options); } catch(e) { if(e instanceof DOMException && e.name === 'AbortError') { console.warn(`Request aborted (${url}`); @@ -91,4 +91,8 @@ export default abstract class MapProvider implements LiveAtlasMapProvider { return json; } + + protected static async getJSON(url: string, signal: AbortSignal) { + return MapProvider.fetchJSON(url, {signal, credentials: 'include'}); + } } diff --git a/src/providers/Pl3xmapMapProvider.ts b/src/providers/Pl3xmapMapProvider.ts index 7c1615d..76e4051 100644 --- a/src/providers/Pl3xmapMapProvider.ts +++ b/src/providers/Pl3xmapMapProvider.ts @@ -190,7 +190,7 @@ export default class Pl3xmapMapProvider extends MapProvider { this.markersAbort = new AbortController(); - const response = await Pl3xmapMapProvider.fetchJSON(url, this.markersAbort.signal); + const response = await Pl3xmapMapProvider.getJSON(url, this.markersAbort.signal); const sets: Map = new Map(); if(!Array.isArray(response)) { @@ -368,7 +368,7 @@ export default class Pl3xmapMapProvider extends MapProvider { this.configurationAbort = new AbortController(); const baseUrl = this.config.pl3xmap, - response = await Pl3xmapMapProvider.fetchJSON(`${baseUrl}tiles/settings.json`, this.configurationAbort.signal); + response = await Pl3xmapMapProvider.getJSON(`${baseUrl}tiles/settings.json`, this.configurationAbort.signal); if (response.error) { throw new Error(response.error); @@ -379,7 +379,7 @@ export default class Pl3xmapMapProvider extends MapProvider { .map((world: any) => world.name); const worldResponses = await Promise.all(worldNames.map(name => - Pl3xmapMapProvider.fetchJSON(`${baseUrl}tiles/${name}/settings.json`, this.configurationAbort!.signal))); + Pl3xmapMapProvider.getJSON(`${baseUrl}tiles/${name}/settings.json`, this.configurationAbort!.signal))); this.store.commit(MutationTypes.SET_SERVER_CONFIGURATION, config); this.store.commit(MutationTypes.SET_SERVER_MESSAGES, Pl3xmapMapProvider.buildMessagesConfig(response)); @@ -407,7 +407,7 @@ export default class Pl3xmapMapProvider extends MapProvider { this.playersAbort = new AbortController(); - const response = await Pl3xmapMapProvider.fetchJSON(url, this.playersAbort.signal), + const response = await Pl3xmapMapProvider.getJSON(url, this.playersAbort.signal), players: Set = new Set(); (response.players || []).forEach((player: any) => {