big bug fixes

This commit is contained in:
Zoe
2024-10-02 02:57:49 -05:00
parent e64b9fba7f
commit 1a6aa40da1
21 changed files with 171 additions and 239 deletions

View File

@@ -11,6 +11,10 @@ import (
fastProxy "github.com/yeqown/fasthttp-reverse-proxy/v2"
)
var (
proxyServer, _ = fastProxy.NewWSReverseProxyWith(fastProxy.WithURL_OptionWS("ws://localhost:3000/_nuxt/"))
)
func init() {
initUi = func(app *fiber.App) {
if !fiber.IsChild() {
@@ -18,39 +22,20 @@ func init() {
}
target := "localhost:3000"
app.Get("/_nuxt/", func(c fiber.Ctx) error {
proxyServer.ServeHTTP(c.Context())
return nil
})
app.All("/*", func(c fiber.Ctx) error {
path := c.Path()
if strings.HasPrefix(path, "/api") {
return c.Next()
}
request := c.Request().URI()
if string(request.RequestURI()) == "/_nuxt/" {
return proxyWebSocket(c, target)
}
requestUri := string(c.Request().URI().RequestURI())
return proxy.Do(c, "http://"+target+string(request.RequestURI()))
return proxy.Do(c, "http://"+target+requestUri)
})
}
}
var proxyServer *fastProxy.ReverseProxy
func proxyWebSocket(c fiber.Ctx, target string) error {
path := c.Path()
// proxyServer, err := fastProxy.NewWSReverseProxyWith(
// fastProxy.WithURL_OptionWS("ws://localhost:3000"+path),
// fastProxy.WithDynamicPath_OptionWS(true, fastProxy.DefaultOverrideHeader),
// )
if proxyServer == nil {
proxyServer, err = fastProxy.NewWSReverseProxyWith(
fastProxy.WithURL_OptionWS("ws://localhost:3000"+path),
fastProxy.WithDynamicPath_OptionWS(true, fastProxy.DefaultOverrideHeader),
)
if err != nil {
panic(err)
}
}
proxyServer.ServeHTTP(c.Context())
return nil
}