feat: fix NocoBase endpoint to justconn.top

This commit is contained in:
nac
2026-08-15 06:03:08 +00:00
parent 6129963256
commit c40e456d7c
12 changed files with 64 additions and 75 deletions
+8 -12
View File
@@ -4,24 +4,20 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
import { DEFAULT_CONFIG, loadConfig } from "../src/config.js";
import { loadCredentials, normalizeApiBaseUrl, saveCredentials } from "../src/credentials.js";
import { loadCredentials, NOCOBASE_API_BASE_URL, saveCredentials } from "../src/credentials.js";
test("normalizes application URLs to the NocoBase API base", () => {
assert.equal(normalizeApiBaseUrl("https://nb.example/app/"), "https://nb.example/app/api");
assert.equal(normalizeApiBaseUrl("http://127.0.0.1:13000/api"), "http://127.0.0.1:13000/api");
assert.throws(() => normalizeApiBaseUrl("http://nb.example"), /HTTPS/i);
assert.throws(() => normalizeApiBaseUrl("https://user:pass@nb.example"), /credentials/i);
});
test("stores and reads credentials from a private file", () => {
test("stores only the Key and always loads the fixed NocoBase endpoint", () => {
const directory = mkdtempSync(join(tmpdir(), "nocobase-mcp-credentials-"));
const path = join(directory, "private", "credentials.json");
saveCredentials({ apiBaseUrl: "https://nb.example", authorizeKey: "secret" }, path);
saveCredentials({ authorizeKey: "secret" }, path);
assert.deepEqual(loadCredentials(path), {
apiBaseUrl: "https://nb.example/api",
apiBaseUrl: NOCOBASE_API_BASE_URL,
authorizeKey: "secret",
});
assert.match(readFileSync(path, "utf8"), /secret/);
assert.deepEqual(JSON.parse(readFileSync(path, "utf8")), { authorizeKey: "secret" });
writeFileSync(path, JSON.stringify({ apiBaseUrl: "https://legacy.example/api", authorizeKey: "secret" }));
assert.equal(loadCredentials(path).apiBaseUrl, NOCOBASE_API_BASE_URL);
if (process.platform !== "win32") {
chmodSync(path, 0o644);
assert.throws(() => loadCredentials(path), /0600/);