m1k1o / neko

A self hosted virtual browser that runs in docker and uses WebRTC.
https://neko.m1k1o.net/
Apache License 2.0
5.98k stars 449 forks source link

Changing Application Route #196

Closed tunahanertekin closed 1 year ago

tunahanertekin commented 1 year ago

Hi again,

Neko is started at URL ip:port by default. I want to change this URL to ip:port/my-route. Is there a trick to change application root in Neko using arguments etc.?

I tried to copy client files (src/dist) to /var/www/my-route and web application is started at ip:port/my-route but it couldn't connect to websocket since it tried to connect to ws-ip:ws-port/my-route/ws, so it was required to change websocket endpoint too but couldn't find the right spot so far. Thanks in advance.

m1k1o commented 1 year ago

Hi. Your path need to end with /, then it will work correctly. You should add redirect on your proxy to path that always ends with /. That's how it's done in neko-rooms.

tunahanertekin commented 1 year ago

Yeah I've just noticed that, thanks. I was also able to change the application route from http.go by adding /xyz prefix before every route. There was just one issue I was faced with, in file server route. I will share the solution I found for that if anyone will have the same struggle and close this issue.

        fs := http.FileServer(http.Dir(conf.Static))
    router.Get("/xyz/*", func(w http.ResponseWriter, r *http.Request) {

                // *** should manipulate path like this to give OS the right file path
        r.URL.Path = r.URL.Path[4:] // 4 is because len("/xyz") = 4 for example

        if _, err := os.Stat(conf.Static + r.URL.Path); !os.IsNotExist(err)  {
            fs.ServeHTTP(w, r)
        } else {
            http.NotFound(w, r)
        }
    })
m1k1o commented 1 year ago

Or it could be done using StripPrefix so i made PR. https://github.com/m1k1o/neko/pull/199