client/web: pass URL prefix to frontend

This allows wouter to route URLs properly when running in CGI mode.

Updates tailscale/corp#14335

Signed-off-by: Will Norris <will@tailscale.com>
pull/10159/head
Will Norris 1 year ago committed by Will Norris
parent 0753ad6cf8
commit 623f669239

@ -8,7 +8,7 @@ import useAuth, { AuthResponse } from "src/hooks/auth"
import useNodeData, { NodeData, NodeUpdate } from "src/hooks/node-data" import useNodeData, { NodeData, NodeUpdate } from "src/hooks/node-data"
import { ReactComponent as TailscaleIcon } from "src/icons/tailscale-icon.svg" import { ReactComponent as TailscaleIcon } from "src/icons/tailscale-icon.svg"
import ProfilePic from "src/ui/profile-pic" import ProfilePic from "src/ui/profile-pic"
import { Link, Route, Switch, useLocation } from "wouter" import { Link, Route, Router, Switch, useLocation } from "wouter"
import DeviceDetailsView from "./views/device-details-view" import DeviceDetailsView from "./views/device-details-view"
export default function App() { export default function App() {
@ -46,6 +46,7 @@ function WebClient({
{/* TODO(sonia): get rid of the conditions here once full/readonly {/* TODO(sonia): get rid of the conditions here once full/readonly
* views live on same components */} * views live on same components */}
{data.DebugMode === "full" && auth?.ok && <Header node={data} />} {data.DebugMode === "full" && auth?.ok && <Header node={data} />}
<Router base={data.URLPrefix}>
<Switch> <Switch>
<Route path="/"> <Route path="/">
<HomeView <HomeView
@ -70,6 +71,7 @@ function WebClient({
<h2 className="mt-8">Page not found</h2> <h2 className="mt-8">Page not found</h2>
</Route> </Route>
</Switch> </Switch>
</Router>
</> </>
) )
} }

@ -15,6 +15,7 @@ export type NodeData = {
IsUnraid: boolean IsUnraid: boolean
UnraidToken: string UnraidToken: string
IPNVersion: string IPNVersion: string
URLPrefix: string
DebugMode: "" | "login" | "full" // empty when not running in any debug mode DebugMode: "" | "login" | "full" // empty when not running in any debug mode
} }

@ -504,6 +504,7 @@ type nodeData struct {
UnraidToken string UnraidToken string
IPNVersion string IPNVersion string
DebugMode string // empty when not running in any debug mode DebugMode string // empty when not running in any debug mode
URLPrefix string // if set, the URL prefix the client is served behind
} }
func (s *Server) serveGetNodeData(w http.ResponseWriter, r *http.Request) { func (s *Server) serveGetNodeData(w http.ResponseWriter, r *http.Request) {
@ -537,6 +538,7 @@ func (s *Server) serveGetNodeData(w http.ResponseWriter, r *http.Request) {
IsUnraid: distro.Get() == distro.Unraid, IsUnraid: distro.Get() == distro.Unraid,
UnraidToken: os.Getenv("UNRAID_CSRF_TOKEN"), UnraidToken: os.Getenv("UNRAID_CSRF_TOKEN"),
IPNVersion: versionShort, IPNVersion: versionShort,
URLPrefix: strings.TrimSuffix(s.pathPrefix, "/"),
DebugMode: debugMode, // TODO(sonia,will): just pass back s.mode directly? DebugMode: debugMode, // TODO(sonia,will): just pass back s.mode directly?
} }
for _, r := range prefs.AdvertiseRoutes { for _, r := range prefs.AdvertiseRoutes {

Loading…
Cancel
Save