chore: improve local debugability of webui by bypassing react-serve proxy

This commit is contained in:
Gareth George
2025-06-22 21:42:10 -07:00
parent 70b91b117b
commit f5b246f502
3 changed files with 20 additions and 3 deletions
+15 -1
View File
@@ -158,9 +158,23 @@ func main() {
mux.Handle("/metrics", auth.RequireAuthentication(metric.GetRegistry().Handler(), authenticator))
// Serve the HTTP gateway
var handler http.Handler = mux
if version == "unknown" { // dev build, enable CORS for local development
handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Connect-Protocol-Version, Connect-Timeout-Ms, Authorization")
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
}
mux.ServeHTTP(w, r)
})
}
server := &http.Server{
Addr: env.BindAddress(),
Handler: h2c.NewHandler(mux, &http2.Server{}), // h2c is HTTP/2 without TLS for grpc-connect support.
Handler: h2c.NewHandler(handler, &http2.Server{}), // h2c is HTTP/2 without TLS for grpc-connect support.
}
zap.S().Infof("starting web server %v", server.Addr)
+2 -1
View File
@@ -3,6 +3,7 @@ import { createConnectTransport } from "@connectrpc/connect-web";
import { createClient } from "@connectrpc/connect";
import { Authentication } from "../gen/ts/v1/authentication_pb";
import { Backrest } from "../gen/ts/v1/service_pb";
import { backendUrl } from "./state/buildcfg";
const tokenKey = "backrest-ui-authToken";
@@ -24,7 +25,7 @@ const fetch = (
};
const transport = createConnectTransport({
baseUrl: "./",
baseUrl: backendUrl,
useBinaryFormat: true,
fetch: fetch as typeof globalThis.fetch,
});
+3 -1
View File
@@ -4,4 +4,6 @@ export const uiBuildVersion = (
process.env.BACKREST_BUILD_VERSION || "dev-snapshot-build"
).trim();
export const isDevBuild = uiBuildVersion === "dev-snapshot-build";
export const pathSeparator = isWindows ? "\\" : "/";
export const pathSeparator = isWindows ? "\\" : "/";
export const backendUrl = process.env.UI_BACKEND_URL || "./";
console.log(`UI OS: ${uios}, Build Version: ${uiBuildVersion}, Backend URL: ${backendUrl}`);