Added different address for express backend

This commit is contained in:
Pax1601 2024-11-12 16:50:01 +01:00
parent 9d225bfc1a
commit 53237c6197
5 changed files with 20 additions and 12 deletions

View File

@ -248,7 +248,7 @@ export class MissionManager {
}
var xhr = new XMLHttpRequest();
xhr.open("GET", window.location.href.split("?")[0].replace("vite/", "") + `api/airbases/${this.#theatre.toLowerCase()}/${callsign}`, true);
xhr.open("GET", getApp().getExpressAddress() + `api/airbases/${this.#theatre.toLowerCase()}/${callsign}`, true);
xhr.responseType = "json";
xhr.onload = () => {
var status = xhr.status;

View File

@ -92,6 +92,14 @@ export class OlympusApp {
}
*/
getExpressAddress() {
return `${window.location.href.split("?")[0].replace("vite/", "").replace("vite", "")}express`
}
getBackendAddress() {
return `${window.location.href.split("?")[0].replace("vite/", "").replace("vite", "")}olympus`
}
start() {
/* Initialize base functionalitites */
this.#shortcutManager = new ShortcutManager(); /* Keep first */
@ -105,8 +113,8 @@ export class OlympusApp {
this.#audioManager = new AudioManager();
/* Set the address of the server */
this.getServerManager().setAddress(window.location.href.split("?")[0].replace("vite/", ""));
this.getAudioManager().setAddress(window.location.href.split("?")[0].replace("vite/", ""));
this.getServerManager().setAddress(this.getBackendAddress());
this.getAudioManager().setAddress(this.getExpressAddress());
/* Check if we are running the latest version */
const request = new Request("https://raw.githubusercontent.com/Pax1601/DCSOlympus/main/version.json");
@ -128,7 +136,7 @@ export class OlympusApp {
});
/* Load the config file from the server */
const configRequest = new Request(window.location.href.split("?")[0].replace("vite/", "") + "resources/config");
const configRequest = new Request(this.getExpressAddress() + "resources/config");
fetch(configRequest)
.then((response) => {
if (response.status === 200) {
@ -164,7 +172,7 @@ export class OlympusApp {
body: JSON.stringify(profile), // Send the data in JSON format
};
fetch(window.location.href.split("?")[0].replace("vite/", "") + `resources/profile/${this.#profileName}`, requestOptions)
fetch(this.getExpressAddress() + `resources/profile/${this.#profileName}`, requestOptions)
.then((response) => {
if (response.status === 200) {
console.log(`Profile ${this.#profileName} saved correctly`);

View File

@ -291,7 +291,7 @@ export function convertDateAndTimeToDate(dateAndTime: DateAndTime) {
export function getGroundElevation(latlng: LatLng, callback: CallableFunction) {
/* Get the ground elevation from the server endpoint */
const xhr = new XMLHttpRequest();
xhr.open("GET", window.location.href.split("?")[0].replace("vite/", "") + `api/elevation/${latlng.lat}/${latlng.lng}`, true);
xhr.open("GET", getApp().getExpressAddress() + `api/elevation/${latlng.lat}/${latlng.lng}`, true);
xhr.timeout = 500; // ms
xhr.responseType = "json";
xhr.onload = () => {

View File

@ -39,7 +39,7 @@ export class ServerManager {
getApp().getShortcutManager().addShortcut("togglePause", {
label: "Pause data update",
callback: () => {
keyUpCallback: () => {
this.setPaused(!this.getPaused());
},
code: "Space"
@ -138,7 +138,7 @@ export class ServerManager {
getConfig(callback: CallableFunction) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", window.location.href.split("?")[0].replace("vite/", "") + "config", true);
xmlHttp.open("GET", getApp().getExpressAddress() + "config", true);
xmlHttp.onload = function (e) {
var data = JSON.parse(xmlHttp.responseText);
callback(data);

View File

@ -56,10 +56,10 @@ export class UnitsManager {
constructor() {
this.#unitDatabase = new UnitDatabase();
this.#unitDatabase.load(window.location.href.split("?")[0].replace("vite/", "") + "api/databases/units/aircraftdatabase", "aircraft");
this.#unitDatabase.load(window.location.href.split("?")[0].replace("vite/", "") + "api/databases/units/helicopterdatabase", "helicopter");
this.#unitDatabase.load(window.location.href.split("?")[0].replace("vite/", "") + "api/databases/units/groundunitdatabase", "groundunit");
this.#unitDatabase.load(window.location.href.split("?")[0].replace("vite/", "") + "api/databases/units/navyunitdatabase", "navyunit");
this.#unitDatabase.load(getApp().getExpressAddress() + "api/databases/units/aircraftdatabase", "aircraft");
this.#unitDatabase.load(getApp().getExpressAddress() + "api/databases/units/helicopterdatabase", "helicopter");
this.#unitDatabase.load(getApp().getExpressAddress() + "api/databases/units/groundunitdatabase", "groundunit");
this.#unitDatabase.load(getApp().getExpressAddress() + "api/databases/units/navyunitdatabase", "navyunit");
CommandModeOptionsChangedEvent.on(() => {
Object.values(this.#units).forEach((unit: Unit) => unit.updateVisibility());