Skip to content

Commit

Permalink
fix: 🐛 fix url mismatch between code and config
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thkruz committed Jan 9, 2024
1 parent 3ce3e18 commit fa5afd0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand Down
11 changes: 6 additions & 5 deletions src/viewer/Earth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,16 @@ class Earth implements SceneComponent {
async init (scene: SatelliteOrbitScene, context: Record<string, any>) {
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,
Expand Down
1 change: 1 addition & 0 deletions src/viewer/ShaderStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ShaderStore {
shaderData: Record<string, string> = {};

constructor (appBaseUrl = '') {
appBaseUrl = appBaseUrl.endsWith('/') ? appBaseUrl : `${appBaseUrl}/`;
this.baseUrl = `${appBaseUrl}${this.basePath}`;
}

Expand Down

0 comments on commit fa5afd0

Please sign in to comment.