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}.`);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ function makeStubWorld({
|
||||
linkCode = "",
|
||||
linkUrl = "",
|
||||
answers = {},
|
||||
endpoint = "http://backend.test:5000",
|
||||
} = {}) {
|
||||
const state = {
|
||||
hooks: new Map(),
|
||||
@@ -48,7 +49,7 @@ function makeStubWorld({
|
||||
syncToken,
|
||||
linkCode,
|
||||
linkUrl,
|
||||
dragonrollApiUrl: "http://backend.test:5000",
|
||||
dragonrollApiUrl: endpoint,
|
||||
};
|
||||
|
||||
const sandbox = {
|
||||
@@ -174,6 +175,17 @@ test("an unpaired world asks Dragonroll for a sign-up link and shows it", async
|
||||
assert.equal(world.setting("linkCode"), "link-code-1", "the code behind the link is kept to ask with");
|
||||
});
|
||||
|
||||
test("a local Dragonroll endpoint keeps the API path the backend mounts", async () => {
|
||||
const world = await makeStubWorld({
|
||||
syncToken: "",
|
||||
endpoint: "http://localhost:5000",
|
||||
answers: { "link/start": { status: "ok", code: "link-code-1", linkUrl: SIGN_UP_LINK } },
|
||||
}).start();
|
||||
|
||||
assert.equal(world.linkStarts()[0].href, "http://localhost:5000/api/link/start",
|
||||
"a local server is asked under /api like any other");
|
||||
});
|
||||
|
||||
test("a world that holds a token neither asks for a link nor waits on one", async () => {
|
||||
const world = await makeStubWorld({
|
||||
answers: { "foundry/sync/status": { status: "ok", campaign: LINKED_CAMPAIGN, worldId: "world-1" } },
|
||||
|
||||
Reference in New Issue
Block a user