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);
|
||||
if (parsedContent !== null && typeof parsedContent === "object") {
|
||||
staticUsers = parsedContent as { [key: string]: string };
|
||||
log(`Serving content for pubkeys in users.yaml`, "blue");
|
||||
}
|
||||
} catch {
|
||||
log(`Could not find or parse a users.yaml config`, "yellow");
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
const config = {
|
||||
@ -48,28 +47,44 @@ const config = {
|
||||
},
|
||||
};
|
||||
|
||||
if (config.relay_urls.length === 0) {
|
||||
log(`No relays configured. Please add at least one relay to RELAY_URLS.`);
|
||||
Deno.exit(1);
|
||||
}
|
||||
const staticUsersConfigured = Object.keys(staticUsers).length > 0;
|
||||
|
||||
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`);
|
||||
export function ensureNecessaryConfigs() {
|
||||
if (config.relay_urls.length === 0) {
|
||||
log(
|
||||
`No relays configured. Please add at least one relay to RELAY_URLS.`,
|
||||
"yellow",
|
||||
);
|
||||
Deno.exit(1);
|
||||
}
|
||||
} else {
|
||||
log(`LDAP not enabled`, "blue");
|
||||
}
|
||||
|
||||
if (Object.keys(staticUsers).length === 0 && !config.ldapEnabled) {
|
||||
log(`Neither static users nor LDAP configured. Nothing to serve.`);
|
||||
Deno.exit(1);
|
||||
if (staticUsersConfigured) {
|
||||
log(`Serving content for pubkeys in users.yaml`, "blue");
|
||||
} 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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Application, Router, send } from "@oak/oak";
|
||||
import { createSubtrTmpDirectories } from "./utils.ts";
|
||||
import config from "./config.ts";
|
||||
import config, { ensureNecessaryConfigs } from "./config.ts";
|
||||
import naddrHandler from "./handlers/naddr.ts";
|
||||
import nprofileHandler from "./handlers/nprofile.ts";
|
||||
import npubHandler from "./handlers/npub.ts";
|
||||
@ -71,6 +71,8 @@ router.get("/assets/:path*", async (ctx) => {
|
||||
}
|
||||
});
|
||||
|
||||
ensureNecessaryConfigs();
|
||||
|
||||
await createSubtrTmpDirectories();
|
||||
|
||||
const app = new Application();
|
||||
|
Loading…
x
Reference in New Issue
Block a user