SaltGUI icon indicating copy to clipboard operation
SaltGUI copied to clipboard

Preserve API_URL in response

Open ddorosh opened this issue 3 years ago • 8 comments

Hi,

first of all I would like to thank you for your great GUI

Is your feature request related to a problem? Please describe. I have SaltGUI with API_URL set as /saltgui. So I type http://example.com/saltgui in my browser to log in. But after logging in I see http://example.com/#minions in my browser.

Describe the solution you'd like Is it possible to set any parameter to see http://example.com/saltgui/#minions in my browser?

Thank you.

ddorosh avatar Sep 16 '22 10:09 ddorosh

first of all I would like to thank you for your great GUI

thx! these compliments are hereby shared with the founders @oliverdunk and @maerteijn and the many contributors

erwindon avatar Sep 16 '22 13:09 erwindon

@ddorosh because SaltGUI is a single page application, there is no actual navigation in the browser. the application updates the address-bar to show the current URL. And that is where it is wrong.

The API_URL is for API calls, it is not for referencing pages. But NAV_URL is. You may have set these 2 to the same value.

I have very little experience in using alternative network setups. But I believe this fix should help:

diff --git a/saltgui/static/scripts/Router.js b/saltgui/static/scripts/Router.js
index 7d950d2c..ae0f4fa3 100644
--- a/saltgui/static/scripts/Router.js
+++ b/saltgui/static/scripts/Router.js
@@ -320,7 +320,7 @@ export class Router {
       }
       // push history state, so that the address bar holds the correct
       // deep-link; and so that we can use the back-button
-      let url = "/";
+      let url = config.NAV_URL ? config.NAV_URL : "/";
       let sep = "?";
       for (const key in pQuery) {
         const value = pQuery[key];

that fix is also available in branch saltguiurl.

this github-issue has been converted to a github-PR

can you give it a try?

can you please share the exact configuration from the rest_cherrypy section in the master files, as well as the content of your file config.js? I might be able to test it myself too...

erwindon avatar Sep 16 '22 21:09 erwindon

Hi @erwindon

thanks for your fast response.

It work with your changes in /saltgui/static/scripts/Router.js. When I set NAV_URL as /saltgui/ I see http://example.com/saltgui/#minions in my browser. Exactly what I wanted. Thank you!

But I noticed one more thing. In spite of I have API_URL set to /saltgui my browser sends requests to http://example.com/static instead of http://example.com/saltgui/static

Untitled 1png

At the same time I have that js from my example at http://example.com/saltgui/static

Untitled 1png

Considering the proxy server it may cause a problem.

ddorosh avatar Sep 17 '22 17:09 ddorosh

@ddorosh the includes for the *.js files are hardcoded in file index.html, the only html file that we have. but they are relative to index.html. because these are relative, they should not need API_URL or NAV_URL.

actually, I just made the URLs for the operating system relative too. variable NAV_URL is now only used to produce the updated URL in the address bar. this is a change in the branch from this PR. can you please pull that one in too and retry? please take an extra look at the OS images. before you login, use shift-refresh to make sure that you actually use the updated code. thx!

erwindon avatar Sep 17 '22 23:09 erwindon

@erwindon unfortunately it didn't help

Furthermore it "cancelled" previous commit and I see http://example.com/#minions again.

So what I did:

  1. undo 8075c4f commit

  2. created saltgui folder inside parent folder for SaltGUI

  3. moved static folder into saltgui folder file_treepng

  4. in index.html file replaced static/ with saltgui/static/

So now I have what I want http://example.com/saltgui/#minions in browser address bar and requests from browser to http://example.com/saltgui/static/...

Untitled2

Thank you for your help and your tips!

ddorosh avatar Sep 18 '22 15:09 ddorosh

@ddorosh

Furthermore it "cancelled" previous commit and I see http://example.com/#minions again.

that is odd, as the additional commit was only about the handling of the OS images. did you accidentality switch to another branch?

in theory, there should be no need to move the source code around when you want another base url. you should be able to instruct salt-api/rest_cherrypy to respond to different url prefixes. look in https://docs.saltproject.io/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html for more details. (as you can determine from the wording, I do not have this working yet...)

I'll keep this PR open to investigate further.

erwindon avatar Sep 18 '22 18:09 erwindon

@erwindon I cloned it from saltguiurl branch. Hope it was correct.

I tried to play with salt-api/rest_cherrypy parameters, but I didn't get what I need

ddorosh avatar Sep 19 '22 06:09 ddorosh

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

sonarqubecloud[bot] avatar Sep 28 '22 22:09 sonarqubecloud[bot]