|
|
@@ -0,0 +1,42 @@
|
|
|
+/**
|
|
|
+ * Where this app is mounted on the origin.
|
|
|
+ *
|
|
|
+ * The same webui .deb is served two ways:
|
|
|
+ * - at the server root -> https://host/ (dev server, direct :8080)
|
|
|
+ * - behind a subpath proxy -> https://host/rag/ (nginx strips /rag)
|
|
|
+ *
|
|
|
+ * The server can't tell us which, because the reverse proxy strips the prefix
|
|
|
+ * before the request arrives. But with hash routing the document path is always
|
|
|
+ * the mount point itself (the route lives in `location.hash`), so the prefix is
|
|
|
+ * recoverable from `location.pathname` alone.
|
|
|
+ *
|
|
|
+ * Every non-router URL must be built on top of this: API calls (`/api/v1/...`),
|
|
|
+ * the session endpoints (`/ui/login`), and the Redoc link (`/docs`).
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * The mount prefix: either '' (mounted at the root) or a prefix with a leading
|
|
|
+ * but no trailing slash, so `mountBase() + '/api/v1/keys'` concatenates cleanly.
|
|
|
+ *
|
|
|
+ * '/' -> '' (server root)
|
|
|
+ * '/rag/' -> '/rag' (subpath, normal case)
|
|
|
+ * '/rag/index.html' -> '/rag' (explicit index)
|
|
|
+ *
|
|
|
+ * Dropping everything after the final '/' handles all three: under hash routing
|
|
|
+ * the path always names the directory the app was served from, optionally plus
|
|
|
+ * an index filename. Computed once — hash navigation never changes pathname.
|
|
|
+ *
|
|
|
+ * Returning '' rather than '/' for the root case matters: '/' would produce
|
|
|
+ * '//api/v1/...', which browsers read as protocol-relative and send to a host
|
|
|
+ * literally named 'api'.
|
|
|
+ */
|
|
|
+const BASE = location.pathname.replace(/\/[^/]*$/, '')
|
|
|
+
|
|
|
+export function mountBase(): string {
|
|
|
+ return BASE
|
|
|
+}
|
|
|
+
|
|
|
+/** Prefix a server-absolute path (must start with '/') with the mount base. */
|
|
|
+export function serverUrl(path: string): string {
|
|
|
+ return BASE + path
|
|
|
+}
|