Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra files (json etc) path not found #99

Closed
warwound opened this issue Oct 31, 2023 · 2 comments
Closed

Extra files (json etc) path not found #99

warwound opened this issue Oct 31, 2023 · 2 comments

Comments

@warwound
Copy link

I have wrapped VirtualSky into a library module for use with Google Web Toolkit (GWT).
My virtualsky object is created and displays in my webpage but virtualsky then attempts to download some extra files and these attempts all fail with a 404 file not found error.

My internal development link is: http://hyperv-debian.lan:8080/VirtualSky/
My web app's webpage contains a single <script> tag for it's javascript: http://hyperv-debian.lan:8080/VirtualSky/virtualskyhost/virtualskyhost.nocache.js
The web app javascript loads and eventually injects two <script> tags into my webpage and then creates the virtualsky object.
The two script tags are for:
https://slowe.github.io/VirtualSky/stuquery.min.js
https://slowe.github.io/VirtualSky/virtualsky.min.js

The 404 requests are for:
http://hyperv-debian.lan:8080/VirtualSky/virtualskyhost/lang/en.json
http://hyperv-debian.lan:8080/VirtualSky/virtualskyhost/virtualsky-planets.js
http://hyperv-debian.lan:8080/VirtualSky/virtualskyhost/lines_latin.json
http://hyperv-debian.lan:8080/VirtualSky/virtualskyhost/stars.json

VirtualSky is generating incorrect paths to these extra files.
And that seems to happen in virtualsky.js around lines 236 to 252:

// Identify the default base directory
this.setDir = function(){
var d = S('script[src*=virtualsky]').attr('src')[0].match(/^.//);
this.dir = d && d[0] || "";
return;
};
this.getDir = function(pattern){
if(typeof pattern!=="string") pattern = "virtualsky";
var d = S('script[src
='+pattern+']').attr('src');
if(typeof d==="string") d = [d];
if(d.length < 1) d = [""];
d = d[0].match(/^.*//);
return d && d[0] || "";
};

this.q = S.query(); // Query string
this.setDir(); // Set the default base directory
this.dir = this.getDir(); // the JS file path

I think VirtualSky expects to find only a single <script> tag containing the text 'virtualsky' and extracts the 'current script path' from this tag.
But my webpage contains three <script> tags and VirtualSky parses the 'src' attribute of the first tag added to the page:
http://hyperv-debian.lan:8080/VirtualSky/virtualskyhost/virtualskyhost.nocache.js
It concludes that the 'current script path' is 'virtualskyhost' and generates the paths to the extra files using this base path.

VirtualSky needs to instead parse the 'src' attribute of the <script> tag that loaded 'virtualsky.min.js'.

@slowe
Copy link
Owner

slowe commented Oct 31, 2023

Looking for virtualsky.min.js breaks if someone was not using the minified version of the script i.e. virtualsky.js. Obviously it isn't ideal. The quickest solution is for you to change the naming of your script path so that it doesn't match virtualsky.

@warwound
Copy link
Author

warwound commented Nov 3, 2023

Thanks for the reply.
I've taken a few days to consider a solution and came up with something that works perfectly and doesn't require a change to my webapp's script path...
I simply remove my webapp's <script> element from the document after my webapp has loaded but before injecting the VirtualSky <script> element into the document.
VirtualSky then correctly finds the <script> tag from which it was loaded and correctly builds the paths to the extras files.

@warwound warwound closed this as completed Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants