mirror of
https://github.com/garethgeorge/backrest.git
synced 2026-08-25 10:26:35 +00:00
chore: improve local debugability of webui by bypassing react-serve proxy
This commit is contained in:
@@ -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
@@ -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,
|
||||
});
|
||||
|
||||
@@ -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}`);
|
||||
Reference in New Issue
Block a user