From fa5afd034aad2f820866004d89133017f0570b25 Mon Sep 17 00:00:00 2001 From: Theodore Kruczek Date: Mon, 8 Jan 2024 20:44:38 -0500 Subject: [PATCH] fix: :bug: fix url mismatch between code and config Basic check to see if there is a trailing slash and if not, then one is automatically added. Also ensures that the baseUrl is used instead of an internal default. Fixes issues #61 --- src/index.ts | 3 +-- src/viewer/Earth.ts | 11 ++++++----- src/viewer/ShaderStore.ts | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index 681bd66..50c03c5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,9 +7,8 @@ import appinfo from './appinfo.json'; import hud from './hud'; async function loadConfig () { - const baseUrl = './'; - const response = await axios.get(`${baseUrl}config.json`); let config = defaultConfig; + const response = await axios.get(`${config.baseUrl}config.json`); if (response.data) { config = { ...defaultConfig, ...response.data, appInfo: appinfo }; } diff --git a/src/viewer/Earth.ts b/src/viewer/Earth.ts index 851e9ac..d4452b2 100644 --- a/src/viewer/Earth.ts +++ b/src/viewer/Earth.ts @@ -94,15 +94,16 @@ class Earth implements SceneComponent { async init (scene: SatelliteOrbitScene, context: Record) { if (context.config) { this.baseUrl = context.config.baseUrl; + this.baseUrl = this.baseUrl.endsWith('/') ? this.baseUrl : `${this.baseUrl}/`; } this.group = new Group(); - const basePath = `${this.baseUrl}images`; - const dayTexture = await this.loadTexture(`${basePath}/earth-blue-marble.jpg`); - const nightTexture = await this.loadTexture(`${basePath}/nightearth-4096.png`); - const bumpTexture = await this.loadTexture(`${basePath}/8081_earthbump4k.jpg`); - const earthSpecularMap = await this.loadTexture(`${basePath}/earth-water.png`); + this.basePath = `${this.baseUrl}images`; + const dayTexture = await this.loadTexture(`${this.basePath}/earth-blue-marble.jpg`); + const nightTexture = await this.loadTexture(`${this.basePath}/nightearth-4096.png`); + const bumpTexture = await this.loadTexture(`${this.basePath}/8081_earthbump4k.jpg`); + const earthSpecularMap = await this.loadTexture(`${this.basePath}/earth-water.png`); const dayMaterial = new MeshPhongMaterial({ map: dayTexture, diff --git a/src/viewer/ShaderStore.ts b/src/viewer/ShaderStore.ts index 6a8d58f..2b16eff 100644 --- a/src/viewer/ShaderStore.ts +++ b/src/viewer/ShaderStore.ts @@ -19,6 +19,7 @@ class ShaderStore { shaderData: Record = {}; constructor (appBaseUrl = '') { + appBaseUrl = appBaseUrl.endsWith('/') ? appBaseUrl : `${appBaseUrl}/`; this.baseUrl = `${appBaseUrl}${this.basePath}`; }