Skip to content

Commit

Permalink
fix(server): reverse proxy error
Browse files Browse the repository at this point in the history
  • Loading branch information
a-wing committed Jan 3, 2024
1 parent 4f69b03 commit bbf33f9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions server/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ import (
"github.com/redis/go-redis/v9"
)

func handler(p http.Handler, token string) func(http.ResponseWriter, *http.Request) {
func handler(p http.Handler, address, token string) func(http.ResponseWriter, *http.Request) {
u, _ := url.Parse(address)
return func(w http.ResponseWriter, r *http.Request) {
if token != "" {
r.Header.Set("Authorization", "Bearer "+token)
}

// Reference: https://liqiang.io/post/implement-reverse-proxy-with-golang
r.Host = u.Host
p.ServeHTTP(w, r)
}
}
Expand Down Expand Up @@ -52,8 +56,8 @@ func NewApi(rdb *redis.Client, secret string, live777Url string, live777Token st
//r.Post("/room/{roomId}/message", handle.CreateMessage)
//r.Get("/room/{roomId}/message", handle.ShowMessage)

r.HandleFunc("/whip/{uuid}", handler(proxy, live777Token))
r.HandleFunc("/whep/{uuid}", handler(proxy, live777Token))
r.HandleFunc("/whip/{uuid}", handler(proxy, live777Url, live777Token))
r.HandleFunc("/whep/{uuid}", handler(proxy, live777Url, live777Token))

r.Handle("/*", http.StripPrefix("/", http.FileServer(helper.NewSinglePageApp("index.html", http.FS(static.Dist)))))
return r
Expand Down

0 comments on commit bbf33f9

Please sign in to comment.