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

Absolute paths to relative #310

Open
StyXman opened this issue Feb 21, 2020 · 4 comments
Open

Absolute paths to relative #310

StyXman opened this issue Feb 21, 2020 · 4 comments

Comments

@StyXman
Copy link

StyXman commented Feb 21, 2020

Hi. I know this is an unusual request, so if you think it's not reasonable, I can understand.

I'm trying to put kosmtik behind a reverse proxy. The problem is that kosmtik returns absolute paths for all the assets, so even when the main page returns fine, all the assets give 404s. Example:

http://dionecanali.hd.free.fr/praetorian/diablo:6789/osm-carto/#16/43.5842/7.1194

Line 6 already has this:

  <script src="/node_modules/leaflet/dist/leaflet-src.js"></script>

Would it be possible to make those paths relative? If I knew enough JS/node, I would do it myself in my own instance and not bother the project with this.

@StyXman
Copy link
Author

StyXman commented Feb 21, 2020

If you follow the link, you'll see I managed some progress :) The current wall I hit is:

TypeError: L.K.Config.project is undefined              DataInspector.js:70:22
    createSidebarPanel http://dionecanali.hd.free.fr/praetorian/diablo:6789/src/front/DataInspector.js:70
    initialize http://dionecanali.hd.free.fr/praetorian/diablo:6789/src/front/DataInspector.js:36
    NewClass http://dionecanali.hd.free.fr/praetorian/diablo:6789/node_modules/leaflet/dist/leaflet-src.js:301
    initialize http://dionecanali.hd.free.fr/praetorian/diablo:6789/src/front/Map.js:16
    NewClass http://dionecanali.hd.free.fr/praetorian/diablo:6789/node_modules/leaflet/dist/leaflet-src.js:301
    <anonymous> http://dionecanali.hd.free.fr/praetorian/diablo:6789/osm-carto/#16/43.5842/7.1194:34

@StyXman
Copy link
Author

StyXman commented Feb 22, 2020

It seems like I managed to do it! Attached is the diff, in case anyone is interested.

diff --git a/src/Config.js b/src/Config.js
index 8378846..845f99f 100644
--- a/src/Config.js
+++ b/src/Config.js
@@ -166,26 +166,26 @@ Config.prototype.parseOptions = function () {
 
 Config.prototype.initStatics = function () {
     this._js = [
-        '/node_modules/leaflet/dist/leaflet-src.js',
-        '/node_modules/leaflet-formbuilder/Leaflet.FormBuilder.js',
-        '/src/front/Core.js',
-        '/config/',
+        '../node_modules/leaflet/dist/leaflet-src.js',
+        '../node_modules/leaflet-formbuilder/Leaflet.FormBuilder.js',
+        '../src/front/Core.js',
+        '../config/',
         './config/',
-        '/src/front/Autocomplete.js',
-        '/src/front/DataInspector.js',
-        '/src/front/MetatilesBounds.js',
-        '/src/front/Sidebar.js',
-        '/src/front/Toolbar.js',
-        '/src/front/FormBuilder.js',
-        '/src/front/Settings.js',
-        '/src/front/Command.js',
-        '/src/front/Map.js'
+        '../src/front/Autocomplete.js',
+        '../src/front/DataInspector.js',
+        '../src/front/MetatilesBounds.js',
+        '../src/front/Sidebar.js',
+        '../src/front/Toolbar.js',
+        '../src/front/FormBuilder.js',
+        '../src/front/Settings.js',
+        '../src/front/Command.js',
+        '../src/front/Map.js'
     ];
     this._css = [
-        '/node_modules/leaflet/dist/leaflet.css',
-        '/src/front/Sidebar.css',
-        '/src/front/Toolbar.css',
-        '/src/front/Core.css'
+        '../node_modules/leaflet/dist/leaflet.css',
+        '../src/front/Sidebar.css',
+        '../src/front/Toolbar.css',
+        '../src/front/Core.css'
     ];
 };
 
diff --git a/src/plugins/base-exporters/index.js b/src/plugins/base-exporters/index.js
index 0b3caad..8a085ee 100644
--- a/src/plugins/base-exporters/index.js
+++ b/src/plugins/base-exporters/index.js
@@ -41,7 +41,7 @@ var BaseExporters = function (config) {
     config.registerExporter('png32', path.join(__dirname, 'PNG.js'));
     config.registerExporter('png256', path.join(__dirname, 'PNG.js'));
     config.on('parseopts', this.parseOpts);
-    config.addJS('/src/plugins/base-exporters/front/export.js');
+    config.addJS('../src/plugins/base-exporters/front/export.js');
 };
 
 BaseExporters.prototype.parseOpts = function (e) {
diff --git a/src/plugins/hash/index.js b/src/plugins/hash/index.js
index cd20a94..77943b4 100644
--- a/src/plugins/hash/index.js
+++ b/src/plugins/hash/index.js
@@ -1,6 +1,6 @@
 var Hash = function (config) {
-    config.addJS('/node_modules/leaflet-hash/leaflet-hash.js');
-    config.addJS('/hash.js');
+    config.addJS('../node_modules/leaflet-hash/leaflet-hash.js');
+    config.addJS('../hash.js');
     config.on('server:init', this.attachRoutes.bind(this));
 };
 

Should I do a PR?

@jmorrison
Copy link

I have also run into this trying to put kosmtik behind an ingress controller. Would be swell to be able to have relative URLs to assets. Is there any reason NOT to make this the default behavior?

@yohanboniface
Copy link
Member

Should I do a PR?

Yes! Sorry for my very late response.

Is there any reason NOT to make this the default behavior?

ERRNOTIME ;)

jmorrison added a commit to jmorrison/kosmtik that referenced this issue Apr 14, 2021
There is an addRoute call to what looks like an absolute URL
'/hash.js' at the end of hash/index.js which StyXman did not change -
and neither will I until and unless testing indicates it is required
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

3 participants