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

[FEAT] Frontend behind path based proxy #56

Closed
aspacca opened this issue Sep 29, 2020 · 10 comments · Fixed by #237
Closed

[FEAT] Frontend behind path based proxy #56

aspacca opened this issue Sep 29, 2020 · 10 comments · Fixed by #237
Labels
enhancement New feature or request

Comments

@aspacca
Copy link
Contributor

aspacca commented Sep 29, 2020

Is your feature request related to a problem? Please describe.
I run scrutiny behind path based nginx proxy

    location ~ ^/scrutiny(/?)(.*) {
         proxy_pass http://127.0.0.1:45000/$2;
    }

Once I load https://mydomain.com/scrutiny the page send a 302 with Location: /web, and then after the redirection the location directive in nginx doesn't match anymore

Describe the solution you'd like
Consider using a base path config for frontend (if possible at all) or build the frontend urls from current url

Additional context
Scrutiny doesn't provide any https listener, so I need to proxy it by nginx

@AnalogJ
Copy link
Owner

AnalogJ commented Sep 29, 2020

Ah, crap. I only use scrutiny with a dedicated subdomain, so I never tested this.
Definitely a worthwhile feature.

Thanks

@AnalogJ AnalogJ added the enhancement New feature or request label Sep 29, 2020
@flying-sausages
Copy link

flying-sausages commented Oct 6, 2020

It would be great to ave an example config alongside these somewhere. A Baseurl would be great for this, I too intend to run this that way and don't want to do a whole rewrite rule ratking.

@AnalogJ
Copy link
Owner

AnalogJ commented Oct 8, 2020

Hey @aspacca @flying-sausages
So I haven't used Nginx a ton (and I almost exclusively use Traefik now) but wouldn't a simple rewrite rule work here?

Basically your browser would see www.yourdomain.com/scrutiny/web/dashboard but nginx would rewrite that request (actually all scrutiny requests) to scrutinycontainer/web/dashboard

Something like https://www.nginx.com/blog/creating-nginx-rewrite-rules/

or is there something else that you'd like me to change on my side?

@aspacca
Copy link
Contributor Author

aspacca commented Oct 8, 2020

@AnalogJ the Location header sent by www.yourdomain.com/scrutiny is absolute: /web, so the browser redirects to www.yourdomain.com/web instead of www.yourdomain.com/scrutiny/web

also api path in Ajax requests is absolute: at the moment I have to "reserve" www.yourdomain.com/web|api instead of being able to serve scrutiny from www.yourdomain.com/scrutiny/web|api

Either introducing a base path/proxy path setup variable, to prepend to the urls, or using relative url built from current location (harder and more tricky in my opinion) could be the solution

@AnalogJ
Copy link
Owner

AnalogJ commented Oct 8, 2020

Hm. sounds like the change needs to be done in the backend server listener

I'm not quite sure where to start on this one, so give me some time to research.

@aspacca
Copy link
Contributor Author

aspacca commented Oct 8, 2020

I'd say that adding a conf with the proxy path/base path where to serve from would be the easiet way
either brutally prefixing every route/redirect with the base path or adding a middleware

I think this gin-gonic/gin#1867 would work, defining contextPathToSkip as the base path from config. still I guess there would be a problem with the redirect

If you tell me which solution you prefer I can open a PR

@aspacca
Copy link
Contributor Author

aspacca commented Oct 8, 2020

https://github.com/gin-gonic/gin#redirects

something like:

basepath := r.Group(ae.Config.BasePath), func(c *gin.Context) {
    c.Request.URL.Path = strings.TrimPrefix(c.Request.URL.Path, ae.Config.BasePath)
    r.HandleContext(c)
})

still to think/test about https://github.com/AnalogJ/scrutiny/blob/master/webapp/backend/pkg/web/server.go#L48

@aspacca
Copy link
Contributor Author

aspacca commented Oct 8, 2020

and then frontend should make requests to relative path

@PriamX
Copy link

PriamX commented Dec 29, 2021

Heya...saw there was quite a bit of momentum in the pull request comments. But all has gone quiet. Just wondering the status on the merge...I'd love to have this feature. Thanks!

@AnalogJ
Copy link
Owner

AnalogJ commented May 9, 2022

reverse proxy + custom path support has now been added. Released in v0.4.1

See docs/TROUBLESHOOTING_REVERSE_PROXY.md for more info.

Thanks for your patience!

@AnalogJ AnalogJ closed this as completed May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
4 participants