fix: resolve dashboard API requests under subpath (#65)
This commit is contained in:
parent
5ca87c1b7c
commit
13fcd42f13
|
|
@ -195,7 +195,7 @@ textarea { resize: vertical; min-height: 120px; }
|
||||||
async function load() {
|
async function load() {
|
||||||
setStatus('Loading…');
|
setStatus('Loading…');
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/v1/context', { headers: { Accept: 'application/json' } });
|
const res = await fetch('api/v1/context', { headers: { Accept: 'application/json' } });
|
||||||
if (!res.ok) throw new Error('HTTP ' + res.status);
|
if (!res.ok) throw new Error('HTTP ' + res.status);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
liveMode = true;
|
liveMode = true;
|
||||||
|
|
@ -264,7 +264,7 @@ textarea { resize: vertical; min-height: 120px; }
|
||||||
async function loadEventStream() {
|
async function loadEventStream() {
|
||||||
setEventStreamStatus('Updating…');
|
setEventStreamStatus('Updating…');
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/v1/events', { headers: { Accept: 'application/json' } });
|
const res = await fetch('api/v1/events', { headers: { Accept: 'application/json' } });
|
||||||
if (!res.ok) throw new Error('HTTP ' + res.status);
|
if (!res.ok) throw new Error('HTTP ' + res.status);
|
||||||
paintEventStream(await res.json());
|
paintEventStream(await res.json());
|
||||||
setEventStreamStatus('Updated ' + fmt(new Date()));
|
setEventStreamStatus('Updated ' + fmt(new Date()));
|
||||||
|
|
@ -275,7 +275,7 @@ textarea { resize: vertical; min-height: 120px; }
|
||||||
|
|
||||||
async function tickWidgets() {
|
async function tickWidgets() {
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/v1/context', { headers: { Accept: 'application/json' } });
|
const res = await fetch('api/v1/context', { headers: { Accept: 'application/json' } });
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
qs('#layout-hint').innerHTML = '<div class="kv"><div class="label">Active view</div><div class="value">' + escapeHtml(data.view || 'dashboard') + '</div><div class="label">Deltas</div><div class="value">' + (data.deltas||[]).length + '</div></div>';
|
qs('#layout-hint').innerHTML = '<div class="kv"><div class="label">Active view</div><div class="value">' + escapeHtml(data.view || 'dashboard') + '</div><div class="label">Deltas</div><div class="value">' + (data.deltas||[]).length + '</div></div>';
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -364,7 +364,7 @@ textarea { resize: vertical; min-height: 120px; }
|
||||||
async function updateRepoMix() {
|
async function updateRepoMix() {
|
||||||
const el = qs('#repo-mix');
|
const el = qs('#repo-mix');
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/v1/context', { headers: { Accept: 'application/json' } });
|
const res = await fetch('api/v1/context', { headers: { Accept: 'application/json' } });
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const repos = data.repos || [];
|
const repos = data.repos || [];
|
||||||
const issues = (data.issues||[]).filter(i=>i.state==='open');
|
const issues = (data.issues||[]).filter(i=>i.state==='open');
|
||||||
|
|
|
||||||
20
tests/test_api_paths.py
Normal file
20
tests/test_api_paths.py
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
|
|
||||||
|
DASHBOARD_HTML = Path(__file__).parent.parent / "frontend" / "index.html"
|
||||||
|
|
||||||
|
|
||||||
|
def test_api_requests_resolve_inside_dashboard_subpath():
|
||||||
|
html = DASHBOARD_HTML.read_text()
|
||||||
|
api_paths = re.findall(r"fetch\(['\"]([^'\"]*api/v1/[^'\"]*)['\"]", html)
|
||||||
|
|
||||||
|
assert api_paths
|
||||||
|
assert {
|
||||||
|
urljoin("https://forge.alexanderwhitestone.com/dashboard/", path)
|
||||||
|
for path in api_paths
|
||||||
|
} == {
|
||||||
|
"https://forge.alexanderwhitestone.com/dashboard/api/v1/context",
|
||||||
|
"https://forge.alexanderwhitestone.com/dashboard/api/v1/events",
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user