fix(rtime): use getApiBase() for subdomain-compatible URL routing
Replace all hardcoded /${space}/rtime paths with getApiBase() which
derives the correct API base from window.location.pathname. This
supports both subdomain routing (demo.rspace.online/rtime) and
path-based fallback (/demo/rtime).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
08cae267fe
commit
2907935c50
|
|
@ -316,12 +316,19 @@ class FolkTimebankApp extends HTMLElement {
|
||||||
this.fetchData();
|
this.fetchData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Derive API base from the current pathname — works for both subdomain and path routing. */
|
||||||
|
private getApiBase(): string {
|
||||||
|
const path = window.location.pathname;
|
||||||
|
const match = path.match(/^(\/[^/]+)?\/rtime/);
|
||||||
|
return match ? match[0] : '/rtime';
|
||||||
|
}
|
||||||
|
|
||||||
disconnectedCallback() {
|
disconnectedCallback() {
|
||||||
if (this.animFrame) cancelAnimationFrame(this.animFrame);
|
if (this.animFrame) cancelAnimationFrame(this.animFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async fetchData() {
|
private async fetchData() {
|
||||||
const base = `/${this.space}/rtime`;
|
const base = this.getApiBase();
|
||||||
try {
|
try {
|
||||||
const [cResp, tResp] = await Promise.all([
|
const [cResp, tResp] = await Promise.all([
|
||||||
fetch(`${base}/api/commitments`),
|
fetch(`${base}/api/commitments`),
|
||||||
|
|
@ -788,7 +795,7 @@ class FolkTimebankApp extends HTMLElement {
|
||||||
|
|
||||||
// Try server-side persist
|
// Try server-side persist
|
||||||
try {
|
try {
|
||||||
const resp = await fetch(`/${this.space}/rtime/api/commitments`, {
|
const resp = await fetch(`${this.getApiBase()}/api/commitments`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ memberName: name, skill, hours, desc }),
|
body: JSON.stringify({ memberName: name, skill, hours, desc }),
|
||||||
|
|
@ -1449,7 +1456,7 @@ class FolkTimebankApp extends HTMLElement {
|
||||||
const description = (this.shadow.getElementById('intentDesc') as HTMLInputElement).value;
|
const description = (this.shadow.getElementById('intentDesc') as HTMLInputElement).value;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resp = await fetch(`/${this.space}/rtime/api/intent`, {
|
const resp = await fetch(`${this.getApiBase()}/api/intent`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ type, skill, hours, description }),
|
body: JSON.stringify({ type, skill, hours, description }),
|
||||||
|
|
@ -1468,7 +1475,7 @@ class FolkTimebankApp extends HTMLElement {
|
||||||
|
|
||||||
private async triggerSolver() {
|
private async triggerSolver() {
|
||||||
try {
|
try {
|
||||||
await fetch(`/${this.space}/rtime/api/solver/run`, { method: 'POST' });
|
await fetch(`${this.getApiBase()}/api/solver/run`, { method: 'POST' });
|
||||||
this.refreshCollaborate();
|
this.refreshCollaborate();
|
||||||
} catch {
|
} catch {
|
||||||
// ignore
|
// ignore
|
||||||
|
|
@ -1476,7 +1483,7 @@ class FolkTimebankApp extends HTMLElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async refreshCollaborate() {
|
private async refreshCollaborate() {
|
||||||
const base = `/${this.space}/rtime`;
|
const base = this.getApiBase();
|
||||||
try {
|
try {
|
||||||
const [iResp, sResp, cResp] = await Promise.all([
|
const [iResp, sResp, cResp] = await Promise.all([
|
||||||
fetch(`${base}/api/intents`),
|
fetch(`${base}/api/intents`),
|
||||||
|
|
@ -1600,7 +1607,7 @@ class FolkTimebankApp extends HTMLElement {
|
||||||
btn.addEventListener('click', async () => {
|
btn.addEventListener('click', async () => {
|
||||||
const resultId = (btn as HTMLElement).dataset.resultId;
|
const resultId = (btn as HTMLElement).dataset.resultId;
|
||||||
try {
|
try {
|
||||||
await fetch(`/${this.space}/rtime/api/solver-results/${resultId}/accept`, { method: 'POST' });
|
await fetch(`${this.getApiBase()}/api/solver-results/${resultId}/accept`, { method: 'POST' });
|
||||||
this.refreshCollaborate();
|
this.refreshCollaborate();
|
||||||
} catch { /* ignore */ }
|
} catch { /* ignore */ }
|
||||||
});
|
});
|
||||||
|
|
@ -1610,7 +1617,7 @@ class FolkTimebankApp extends HTMLElement {
|
||||||
btn.addEventListener('click', async () => {
|
btn.addEventListener('click', async () => {
|
||||||
const resultId = (btn as HTMLElement).dataset.resultId;
|
const resultId = (btn as HTMLElement).dataset.resultId;
|
||||||
try {
|
try {
|
||||||
await fetch(`/${this.space}/rtime/api/solver-results/${resultId}/reject`, { method: 'POST' });
|
await fetch(`${this.getApiBase()}/api/solver-results/${resultId}/reject`, { method: 'POST' });
|
||||||
this.refreshCollaborate();
|
this.refreshCollaborate();
|
||||||
} catch { /* ignore */ }
|
} catch { /* ignore */ }
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -427,6 +427,6 @@ export const timeModule: RSpaceModule = {
|
||||||
{ path: "collaborate", name: "Collaborate", icon: "🤝", description: "Intent-routed collaboration matching" },
|
{ path: "collaborate", name: "Collaborate", icon: "🤝", description: "Intent-routed collaboration matching" },
|
||||||
],
|
],
|
||||||
onboardingActions: [
|
onboardingActions: [
|
||||||
{ label: "Pledge Hours", icon: "⏳", description: "Add a commitment to the pool", type: 'create', href: '/{space}/rtime' },
|
{ label: "Pledge Hours", icon: "⏳", description: "Add a commitment to the pool", type: 'create', href: '/rtime' },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue