kdjskdjsk
This commit is contained in:
@@ -43,9 +43,8 @@ settings screen re-displays it after a page reload, the window being closed, or
|
||||
example one pasted while Dragonroll was restarting — retrying it at world startup and once a minute
|
||||
until the world finishes linking.
|
||||
|
||||
For a local backend, use `http://localhost:5000`; the module omits `/api` and the backend accepts
|
||||
the local pairing route at its root. Character synchronization works without the optional snapshot
|
||||
bridge. Configure that bridge only if you also need the read-only world snapshot API described below.
|
||||
For a local backend, use `http://localhost:5000`; the module adds `/api` like it does for any other
|
||||
server. Character synchronization works without the optional snapshot bridge. Configure that bridge only if you also need the read-only world snapshot API described below.
|
||||
|
||||
**Dragonroll Pairing Status** in the module settings always says whether this browser holds a pairing
|
||||
and, once Dragonroll has answered `GET /api/foundry/sync/status`, which campaign the world is
|
||||
|
||||
@@ -196,24 +196,33 @@ function dragonrollEndpoint(path) {
|
||||
|
||||
const apiBase = new URL(endpoint);
|
||||
const basePath = apiBase.pathname.replace(/\/+$/, "");
|
||||
const isLocalBackend = ["localhost", "127.0.0.1", "[::1]"].includes(apiBase.hostname)
|
||||
&& apiBase.port === "5000";
|
||||
const hasApiPath = basePath.endsWith("/api");
|
||||
apiBase.pathname = `${hasApiPath || isLocalBackend ? basePath : `${basePath}/api`}/`;
|
||||
apiBase.pathname = `${hasApiPath ? basePath : `${basePath}/api`}/`;
|
||||
apiBase.search = "";
|
||||
apiBase.hash = "";
|
||||
return new URL(path.replace(/^\/+/, ""), apiBase);
|
||||
}
|
||||
|
||||
// A Dragonroll that is not there, or a URL that points at the web app instead of
|
||||
// the API, answers with HTML. Say that plainly instead of a JSON parse error.
|
||||
async function readDragonrollJson(response, url) {
|
||||
try {
|
||||
return await response.json();
|
||||
} catch {
|
||||
throw new Error(`Dragonroll answered HTTP ${response.status} at ${url} but not with JSON. Check the Dragonroll Endpoint setting.`);
|
||||
}
|
||||
}
|
||||
|
||||
async function postDragonroll(path, body, token = "") {
|
||||
const headers = { "Content-Type": "application/json" };
|
||||
if (token) headers.Authorization = `Bearer ${token}`;
|
||||
const response = await fetch(dragonrollEndpoint(path), {
|
||||
const url = dragonrollEndpoint(path);
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const result = await response.json();
|
||||
const result = await readDragonrollJson(response, url);
|
||||
if (!response.ok || result.status !== "ok") {
|
||||
throw new Error(result.msg || `Dragonroll returned HTTP ${response.status}.`);
|
||||
}
|
||||
@@ -221,10 +230,11 @@ async function postDragonroll(path, body, token = "") {
|
||||
}
|
||||
|
||||
async function getDragonroll(path, token) {
|
||||
const response = await fetch(dragonrollEndpoint(path), {
|
||||
const url = dragonrollEndpoint(path);
|
||||
const response = await fetch(url, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
const result = await response.json();
|
||||
const result = await readDragonrollJson(response, url);
|
||||
if (!response.ok || result.status !== "ok") {
|
||||
throw new Error(result.msg || `Dragonroll returned HTTP ${response.status}.`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user