From 5a9e03db2c12af5367ea901f23d87a621a1bd5c9 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Wed, 22 Jul 2020 11:07:32 -0700 Subject: [PATCH] Use relative URLs throughout the UI To allow serving from a subdirectory using a reverse proxy. --- ui/components/all-parameters.ts | 2 +- ui/devices-page.ts | 2 +- ui/faults-page.ts | 2 +- ui/files-page.ts | 4 ++-- ui/permissions-page.ts | 2 +- ui/pie-chart-component.ts | 4 ++-- ui/presets-page.ts | 6 +++--- ui/provisions-page.ts | 2 +- ui/store.ts | 26 +++++++++++++------------- ui/users-page.ts | 2 +- ui/virtual-parameters-page.ts | 2 +- ui/wizard-page.ts | 6 +++--- 12 files changed, 30 insertions(+), 30 deletions(-) diff --git a/ui/components/all-parameters.ts b/ui/components/all-parameters.ts index cb006c3..3f15872 100644 --- a/ui/components/all-parameters.ts +++ b/ui/components/all-parameters.ts @@ -140,7 +140,7 @@ const component: ClosureComponent = (): Component => { m( "a.download-csv", { - href: `/api/devices/${encodeURIComponent( + href: `api/devices/${encodeURIComponent( device["DeviceID.ID"].value[0] )}.csv`, download: "", diff --git a/ui/devices-page.ts b/ui/devices-page.ts index 5d1ae34..e76553e 100644 --- a/ui/devices-page.ts +++ b/ui/devices-page.ts @@ -47,7 +47,7 @@ const memoizedGetSortable = memoize(p => { const getDownloadUrl = memoize((filter, indexParameters) => { const columns = {}; for (const p of indexParameters) columns[p.label] = stringify(p.parameter); - return `/api/devices.csv?${m.buildQueryString({ + return `api/devices.csv?${m.buildQueryString({ filter: stringify(filter), columns: JSON.stringify(columns) })}`; diff --git a/ui/faults-page.ts b/ui/faults-page.ts index c13730a..89cff62 100644 --- a/ui/faults-page.ts +++ b/ui/faults-page.ts @@ -51,7 +51,7 @@ const getDownloadUrl = memoize(filter => { attr.id === "timestamp" ? `DATE_STRING(${attr.id})` : attr.id; } - return `/api/faults.csv?${m.buildQueryString({ + return `api/faults.csv?${m.buildQueryString({ filter: stringify(filter), columns: JSON.stringify(cols) })}`; diff --git a/ui/files-page.ts b/ui/files-page.ts index 498abbc..152450d 100644 --- a/ui/files-page.ts +++ b/ui/files-page.ts @@ -108,7 +108,7 @@ function putActionHandler(action, _object): Promise { .xhrRequest({ method: "PUT", headers: headers, - url: `/api/files/${encodeURIComponent(id)}`, + url: `api/files/${encodeURIComponent(id)}`, serialize: body => body, // Identity function to prevent JSON.parse on blob data body: file }) @@ -132,7 +132,7 @@ function putActionHandler(action, _object): Promise { const getDownloadUrl = memoize(filter => { const cols = {}; for (const attr of attributes) cols[attr.label] = attr.id; - return `/api/files.csv?${m.buildQueryString({ + return `api/files.csv?${m.buildQueryString({ filter: stringify(filter), columns: JSON.stringify(cols) })}`; diff --git a/ui/permissions-page.ts b/ui/permissions-page.ts index d909b23..e4f9755 100644 --- a/ui/permissions-page.ts +++ b/ui/permissions-page.ts @@ -157,7 +157,7 @@ const formData = { const getDownloadUrl = memoize(filter => { const cols = {}; for (const attr of attributes) cols[attr.label] = attr.id; - return `/api/permissions.csv?${m.buildQueryString({ + return `api/permissions.csv?${m.buildQueryString({ filter: stringify(filter), columns: JSON.stringify(cols) })}`; diff --git a/ui/pie-chart-component.ts b/ui/pie-chart-component.ts index f35069b..812a11c 100644 --- a/ui/pie-chart-component.ts +++ b/ui/pie-chart-component.ts @@ -49,7 +49,7 @@ function drawChart(chartData): Children { m( "a", { - href: `/#!/devices/?${m.buildQueryString({ + href: `#!/devices/?${m.buildQueryString({ filter: memoizedStringify(slice["filter"]) })}` }, @@ -89,7 +89,7 @@ function drawChart(chartData): Children { m( "a", { - "xlink:href": `/#!/devices/?${m.buildQueryString({ + "xlink:href": `#!/devices/?${m.buildQueryString({ filter: memoizedStringify(slice["filter"]) })}` }, diff --git a/ui/presets-page.ts b/ui/presets-page.ts index d185bf3..bb8d561 100644 --- a/ui/presets-page.ts +++ b/ui/presets-page.ts @@ -134,7 +134,7 @@ const formData = { const getDownloadUrl = memoize(filter => { const cols = {}; for (const attr of attributes) cols[attr.label] = attr.id; - return `/api/presets.csv?${m.buildQueryString({ + return `api/presets.csv?${m.buildQueryString({ filter: stringify(filter), columns: JSON.stringify(cols) })}`; @@ -240,7 +240,7 @@ export const component: ClosureComponent = (): Component => { const valueCallback = (attr, preset): {} => { if (attr.id === "precondition") { - let devicesUrl = "/#!/devices"; + let devicesUrl = "#!/devices"; if (preset["precondition"].length) { devicesUrl += `?${m.buildQueryString({ filter: preset["precondition"] @@ -259,7 +259,7 @@ export const component: ClosureComponent = (): Component => { return m( "a", { - href: `/#!/admin/provisions?${m.buildQueryString({ + href: `#!/admin/provisions?${m.buildQueryString({ filter: `Q("ID", "${preset["provision"]}")` })}` }, diff --git a/ui/provisions-page.ts b/ui/provisions-page.ts index 091805a..4db92ba 100644 --- a/ui/provisions-page.ts +++ b/ui/provisions-page.ts @@ -114,7 +114,7 @@ const formData = { const getDownloadUrl = memoize(filter => { const cols = {}; for (const attr of attributes) cols[attr.label] = attr.id; - return `/api/provisions.csv?${m.buildQueryString({ + return `api/provisions.csv?${m.buildQueryString({ filter: stringify(filter), columns: JSON.stringify(cols) })}`; diff --git a/ui/store.ts b/ui/store.ts index 467e092..c073cf6 100644 --- a/ui/store.ts +++ b/ui/store.ts @@ -91,7 +91,7 @@ class QueryResponse { function checkConnection(): void { m.request({ - url: "/status", + url: "status", method: "GET", background: true, extract: xhr => { @@ -387,7 +387,7 @@ export function fulfill(accessTimestamp, _fulfillTimestamp): Promise { xhrRequest({ method: "HEAD", url: - `/api/${resourceType}/?` + + `api/${resourceType}/?` + m.buildQueryString({ filter: memoizedStringify(filter) }), @@ -433,7 +433,7 @@ export function fulfill(accessTimestamp, _fulfillTimestamp): Promise { xhrRequest({ method: "GET", url: - `/api/${resourceType}/?` + + `api/${resourceType}/?` + m.buildQueryString({ filter: memoizedStringify(filter), limit: 1, @@ -526,7 +526,7 @@ export function fulfill(accessTimestamp, _fulfillTimestamp): Promise { xhrRequest({ method: "GET", url: - `/api/${resourceType}/?` + + `api/${resourceType}/?` + m.buildQueryString({ filter: memoizedStringify(combinedFilterDiff) }) @@ -588,7 +588,7 @@ export function postTasks(deviceId, tasks): Promise { return xhrRequest({ method: "POST", - url: `/api/devices/${encodeURIComponent(deviceId)}/tasks`, + url: `api/devices/${encodeURIComponent(deviceId)}/tasks`, body: tasks, extract: xhr => { if (xhr.status !== 200) throw new Error(xhr.response); @@ -609,7 +609,7 @@ export function postTasks(deviceId, tasks): Promise { export function updateTags(deviceId, tags): Promise { return xhrRequest({ method: "POST", - url: `/api/devices/${encodeURIComponent(deviceId)}/tags`, + url: `api/devices/${encodeURIComponent(deviceId)}/tags`, body: tags }); } @@ -617,7 +617,7 @@ export function updateTags(deviceId, tags): Promise { export function deleteResource(resourceType, id): Promise { return xhrRequest({ method: "DELETE", - url: `/api/${resourceType}/${encodeURIComponent(id)}` + url: `api/${resourceType}/${encodeURIComponent(id)}` }); } @@ -626,7 +626,7 @@ export function putResource(resourceType, id, object): Promise { return xhrRequest({ method: "PUT", - url: `/api/${resourceType}/${encodeURIComponent(id)}`, + url: `api/${resourceType}/${encodeURIComponent(id)}`, body: object }); } @@ -646,7 +646,7 @@ export function resourceExists(resource, id): Promise { return xhrRequest({ method: "HEAD", url: - `/api/${resource}/?` + + `api/${resource}/?` + m.buildQueryString({ filter: memoizedStringify(filter) }), @@ -669,7 +669,7 @@ export function changePassword( if (authPassword) body["authPassword"] = authPassword; return xhrRequest({ method: "PUT", - url: `/api/users/${username}/password`, + url: `api/users/${username}/password`, background: true, body }); @@ -678,7 +678,7 @@ export function changePassword( export function logIn(username, password): Promise { return xhrRequest({ method: "POST", - url: "/login", + url: "login", background: true, body: { username, password } }); @@ -687,13 +687,13 @@ export function logIn(username, password): Promise { export function logOut(): Promise { return xhrRequest({ method: "POST", - url: "/logout" + url: "logout" }); } export function ping(host): Promise<{}> { return xhrRequest({ - url: `/api/ping/${encodeURIComponent(host)}`, + url: `api/ping/${encodeURIComponent(host)}`, background: true }); } diff --git a/ui/users-page.ts b/ui/users-page.ts index 29766bd..5765791 100644 --- a/ui/users-page.ts +++ b/ui/users-page.ts @@ -137,7 +137,7 @@ const getDownloadUrl = memoize(filter => { const cols = {}; for (const attr of attributes) cols[attr.label] = attr.id; - return `/api/users.csv?${m.buildQueryString({ + return `api/users.csv?${m.buildQueryString({ filter: stringify(filter), columns: JSON.stringify(cols) })}`; diff --git a/ui/virtual-parameters-page.ts b/ui/virtual-parameters-page.ts index daac266..d29bf2d 100644 --- a/ui/virtual-parameters-page.ts +++ b/ui/virtual-parameters-page.ts @@ -114,7 +114,7 @@ const formData = { const getDownloadUrl = memoize(filter => { const cols = {}; for (const attr of attributes) cols[attr.label] = attr.id; - return `/api/virtualParameters.csv?${m.buildQueryString({ + return `api/virtualParameters.csv?${m.buildQueryString({ filter: stringify(filter), columns: JSON.stringify(cols) })}`; diff --git a/ui/wizard-page.ts b/ui/wizard-page.ts index 61086a6..e691d84 100644 --- a/ui/wizard-page.ts +++ b/ui/wizard-page.ts @@ -21,7 +21,7 @@ import m, { ClosureComponent, Component } from "mithril"; import * as notifications from "./notifications"; export async function init(): Promise<{}> { - return m.request({ url: "/init" }); + return m.request({ url: "init" }); } export const component: ClosureComponent = (vnode): Component => { @@ -82,12 +82,12 @@ export const component: ClosureComponent = (vnode): Component => { m.request({ method: "POST", - url: "/init", + url: "init", body: opts }) .then(() => { setTimeout(() => { - m.request({ url: "/init" }).then(o => { + m.request({ url: "init" }).then(o => { e.target.disabled = false; options = o; notifications.push("success", "Initialization complete", {