Fix hardcoded API paths: inject URLs via url_for() in template, read from window.NEUSICIAN_URLS in api.js

This commit is contained in:
c0dev0id
2026-06-24 18:19:56 +02:00
parent 097d4488ef
commit c4804f0b55
3 changed files with 25 additions and 6 deletions

View File

@@ -1,3 +1,13 @@
const U = window.NEUSICIAN_URLS ?? {
astlog: '/sompyle/astlog',
score: '/sompyle/score.spls',
status: '/sompyle/status.json',
result: '/sompyle/result.mp3',
submit: '/sompyle',
};
export const URLS = U;
function authHeader(credentials) {
if (!credentials) return {};
const b64 = btoa(`${credentials.username}:${credentials.password}`);
@@ -5,7 +15,7 @@ function authHeader(credentials) {
}
export async function fetchAstLog(credentials) {
const res = await fetch('/sompyle/astlog', {
const res = await fetch(U.astlog, {
headers: authHeader(credentials),
});
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
@@ -13,7 +23,7 @@ export async function fetchAstLog(credentials) {
}
export async function fetchScoreText(credentials) {
const res = await fetch('/sompyle/score.spls', {
const res = await fetch(U.score, {
headers: authHeader(credentials),
});
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
@@ -21,7 +31,7 @@ export async function fetchScoreText(credentials) {
}
export async function putScoreText(text, credentials) {
const res = await fetch('/sompyle/score.spls', {
const res = await fetch(U.score, {
method: 'PUT',
headers: {
...authHeader(credentials),
@@ -34,7 +44,7 @@ export async function putScoreText(text, credentials) {
}
export async function fetchStatus(credentials) {
const res = await fetch('/sompyle/status.json', {
const res = await fetch(U.status, {
headers: authHeader(credentials),
});
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);