Skip to content

Commit 2ad1eb7

Browse files
committed
Make API_BASEPATH configurable based on PATH_PREFIX
1 parent 4d2c9d1 commit 2ad1eb7

File tree

6 files changed

+14
-7
lines changed

6 files changed

+14
-7
lines changed

main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"math"
1313
"net/http"
1414
"net/url"
15+
"path"
1516
"sort"
1617
"strconv"
1718
"strings"
@@ -152,9 +153,11 @@ func cmdAPI(prometheusURL, prometheusExternal, apiURL *url.URL, routePrefix, uiR
152153
if err := tmpl.Execute(w, struct {
153154
PrometheusURL string
154155
PathPrefix string
156+
APIBasepath string
155157
}{
156158
PrometheusURL: prometheusExternal.String(),
157159
PathPrefix: uiRoutePrefix,
160+
APIBasepath: path.Join(uiRoutePrefix, "/api/v1"),
158161
}); err != nil {
159162
log.Println(err)
160163
return
@@ -166,9 +169,11 @@ func cmdAPI(prometheusURL, prometheusExternal, apiURL *url.URL, routePrefix, uiR
166169
if err := tmpl.Execute(w, struct {
167170
PrometheusURL string
168171
PathPrefix string
172+
APIBasepath string
169173
}{
170174
PrometheusURL: prometheusExternal.String(),
171175
PathPrefix: uiRoutePrefix,
176+
APIBasepath: path.Join(uiRoutePrefix, "/api/v1"),
172177
}); err != nil {
173178
log.Println(err)
174179
}

ui/public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
-->
2424
<title>Pyrra</title>
2525
<script>window.PATH_PREFIX = {{.PathPrefix}}</script>
26+
<script>window.API_BASEPATH = {{.APIBasepath}}</script>
2627
<script>window.PROMETHEUS_URL = {{.PrometheusURL}}</script>
2728
</head>
2829
<body>

ui/src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import Detail from './pages/Detail'
66
// @ts-ignore - this is passed from the HTML template.
77
export const PATH_PREFIX: string = window.PATH_PREFIX;
88
// @ts-ignore - this is passed from the HTML template.
9+
export const API_BASEPATH: string = window.API_BASEPATH;
10+
// @ts-ignore - this is passed from the HTML template.
911
export const PROMETHEUS_URL: string = window.PROMETHEUS_URL;
1012

1113
const App = () => {
@@ -38,7 +40,6 @@ export const dateFormatter = (timeRange: number) => (t: number): string => {
3840
}
3941

4042
return `${hourLeading}:${minuteLeading}`
41-
4243
}
4344

4445
export const dateFormatterFull = (t: number): string => {

ui/src/components/AlertsTable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { OverlayTrigger, Table, Tooltip as OverlayTooltip } from 'react-bootstrap'
22
import React, { useEffect, useMemo, useState } from 'react'
3-
import { formatDuration, PROMETHEUS_URL, PATH_PREFIX } from '../App'
3+
import { API_BASEPATH, formatDuration, PROMETHEUS_URL } from '../App'
44
import { Configuration, MultiBurnrateAlert, Objective, ObjectivesApi } from '../client'
55
import { IconExternal } from './Icons'
66
import { labelsString } from "../labels";
@@ -12,7 +12,7 @@ interface AlertsTableProps {
1212

1313
const AlertsTable = ({ objective, grouping }: AlertsTableProps): JSX.Element => {
1414
const api = useMemo(() => {
15-
return new ObjectivesApi(new Configuration({ basePath: `./api/v1` }))
15+
return new ObjectivesApi(new Configuration({ basePath: API_BASEPATH }))
1616
}, [])
1717

1818
const [alerts, setAlerts] = useState<MultiBurnrateAlert[]>([])

ui/src/pages/Detail.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
ObjectiveStatusAvailability,
1010
ObjectiveStatusBudget
1111
} from '../client'
12-
import { formatDuration, parseDuration, PATH_PREFIX } from '../App'
12+
import { API_BASEPATH, formatDuration, parseDuration } from '../App'
1313
import Navbar from '../components/Navbar'
1414
import { parseLabels } from "../labels";
1515
import ErrorBudgetGraph from "../components/graphs/ErrorBudgetGraph";
@@ -22,7 +22,7 @@ const Detail = () => {
2222
const query = new URLSearchParams(useLocation().search)
2323

2424
const api = useMemo(() => {
25-
return new ObjectivesApi(new Configuration({ basePath: `./api/v1` }))
25+
return new ObjectivesApi(new Configuration({ basePath: API_BASEPATH }))
2626
}, [])
2727

2828
const queryExpr = query.get('expr')

ui/src/pages/List.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect, useMemo, useReducer, useState } from 'react'
22
import { Badge, Col, Container, OverlayTrigger, Row, Spinner, Table, Tooltip as OverlayTooltip } from 'react-bootstrap'
33
import { Configuration, Objective, ObjectivesApi, ObjectiveStatus } from '../client'
4-
import { formatDuration, PATH_PREFIX } from '../App'
4+
import { API_BASEPATH, formatDuration } from '../App'
55
import { Link, useHistory } from 'react-router-dom'
66
import Navbar from '../components/Navbar'
77
import { IconArrowDown, IconArrowUp, IconArrowUpDown } from '../components/Icons'
@@ -159,7 +159,7 @@ interface TableSorting {
159159

160160
const List = () => {
161161
const api = useMemo(() => {
162-
return new ObjectivesApi(new Configuration({ basePath: `./api/v1` }))
162+
return new ObjectivesApi(new Configuration({ basePath: API_BASEPATH }))
163163
}, [])
164164

165165
const history = useHistory()

0 commit comments

Comments
 (0)