RAW_WS_PROXY_URL=http://localhost:17071, RAW_WS=8080 to use web

master
Bel LaPointe 2023-04-09 11:53:21 -06:00
parent f3cbfa1c48
commit 39f6bc8ed9
3 changed files with 37 additions and 20 deletions

View File

@ -1,27 +1,20 @@
feedback:
addr: :17071
ttsurl: http://localhost:15002
broadcast:
message: hi
users:
bel:
meta:
lasttsms: 1681062770999
lastlag: 12
state:
player: 0
message: "hi"
alias: driver
meta:
tsms: 1
lastlag: 2
message: hi
gm:
alias: ""
lastalias: ""
vote: ""
players:
- buttons:
up: "w"
down: "s"
left: "a"
right: "d"
l: "q"
r: "e"
a: "1"
b: "2"
x: "3"
y: "4"
- transformation: {}
quiet: false
broadcast:
message: hi

View File

@ -27,10 +27,10 @@
function noopcallback(responseBody, responseStatus) {
}
setInterval(() => {
http("GET", `/proxy?user=${document.getElementById("user")}`, (b, s) => {
http("GET", `/proxy?user=${document.getElementById("user").value}`, (b, s) => {
if (s != 200)
return
document.getElementById("ntfy").innerHTML = b.replace("\n", "<br>")
document.getElementById("ntfy").innerHTML = b.replaceAll("\n", "<br>")
}, null)
}, 1500)
</script>

View File

@ -6,11 +6,18 @@ import (
"fmt"
"log"
"net/http"
"net/http/httputil"
"net/url"
"os"
"strings"
"github.com/gorilla/websocket"
)
var (
FlagWSProxy = os.Getenv("RAW_WS_PROXY_URL")
)
type WS struct {
ctx context.Context
can context.CancelFunc
@ -72,10 +79,27 @@ func (ws WS) serveHTTP(w http.ResponseWriter, r *http.Request) error {
case "/api/ws":
return ws.serveWS(w, r)
}
if strings.HasPrefix(r.URL.Path, "/proxy") {
return ws.serveProxy(w, r)
}
http.NotFound(w, r)
return nil
}
func (ws WS) serveProxy(w http.ResponseWriter, r *http.Request) error {
u, err := url.Parse(FlagWSProxy)
if err != nil {
return err
}
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/proxy")
if r.URL.Path == "" {
r.URL.Path = "/"
}
proxy := httputil.NewSingleHostReverseProxy(u)
proxy.ServeHTTP(w, r)
return nil
}
//go:embed public/root.html
var rootHTML string