Improve config processing
This commit is contained in:
parent
0096f3cae3
commit
b7974c8610
55
config.ts
55
config.ts
@ -28,10 +28,9 @@ try {
|
|||||||
const parsedContent = parseYaml(fileContent);
|
const parsedContent = parseYaml(fileContent);
|
||||||
if (parsedContent !== null && typeof parsedContent === "object") {
|
if (parsedContent !== null && typeof parsedContent === "object") {
|
||||||
staticUsers = parsedContent as { [key: string]: string };
|
staticUsers = parsedContent as { [key: string]: string };
|
||||||
log(`Serving content for pubkeys in users.yaml`, "blue");
|
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
log(`Could not find or parse a users.yaml config`, "yellow");
|
// Nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
@ -48,28 +47,44 @@ const config = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (config.relay_urls.length === 0) {
|
const staticUsersConfigured = Object.keys(staticUsers).length > 0;
|
||||||
log(`No relays configured. Please add at least one relay to RELAY_URLS.`);
|
|
||||||
Deno.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.ldapEnabled) {
|
export function ensureNecessaryConfigs() {
|
||||||
if (
|
if (config.relay_urls.length === 0) {
|
||||||
config.ldap.url && config.ldap.bindDN && config.ldap.password &&
|
log(
|
||||||
config.ldap.searchDN
|
`No relays configured. Please add at least one relay to RELAY_URLS.`,
|
||||||
) {
|
"yellow",
|
||||||
log(`Serving content for pubkeys from ${config.ldap.url}`, "blue");
|
);
|
||||||
} else {
|
|
||||||
log(`The LDAP config is incomplete`);
|
|
||||||
Deno.exit(1);
|
Deno.exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
log(`LDAP not enabled`, "blue");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Object.keys(staticUsers).length === 0 && !config.ldapEnabled) {
|
if (staticUsersConfigured) {
|
||||||
log(`Neither static users nor LDAP configured. Nothing to serve.`);
|
log(`Serving content for pubkeys in users.yaml`, "blue");
|
||||||
Deno.exit(1);
|
} else {
|
||||||
|
log(`Could not find or parse a users.yaml config`, "gray");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.ldapEnabled) {
|
||||||
|
if (
|
||||||
|
config.ldap.url && config.ldap.bindDN && config.ldap.password &&
|
||||||
|
config.ldap.searchDN
|
||||||
|
) {
|
||||||
|
log(`Serving content for pubkeys from ${config.ldap.url}`, "blue");
|
||||||
|
} else {
|
||||||
|
log(`The LDAP config is incomplete`);
|
||||||
|
Deno.exit(1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log(`LDAP not enabled`, "blue");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!staticUsersConfigured && !config.ldapEnabled) {
|
||||||
|
log(
|
||||||
|
`Neither static users nor LDAP configured. Nothing to serve.`,
|
||||||
|
"yellow",
|
||||||
|
);
|
||||||
|
Deno.exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default config;
|
export default config;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Application, Router, send } from "@oak/oak";
|
import { Application, Router, send } from "@oak/oak";
|
||||||
import { createSubtrTmpDirectories } from "./utils.ts";
|
import { createSubtrTmpDirectories } from "./utils.ts";
|
||||||
import config from "./config.ts";
|
import config, { ensureNecessaryConfigs } from "./config.ts";
|
||||||
import naddrHandler from "./handlers/naddr.ts";
|
import naddrHandler from "./handlers/naddr.ts";
|
||||||
import nprofileHandler from "./handlers/nprofile.ts";
|
import nprofileHandler from "./handlers/nprofile.ts";
|
||||||
import npubHandler from "./handlers/npub.ts";
|
import npubHandler from "./handlers/npub.ts";
|
||||||
@ -71,6 +71,8 @@ router.get("/assets/:path*", async (ctx) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ensureNecessaryConfigs();
|
||||||
|
|
||||||
await createSubtrTmpDirectories();
|
await createSubtrTmpDirectories();
|
||||||
|
|
||||||
const app = new Application();
|
const app = new Application();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user