add auth-node endpoint
This commit is contained in:
parent
d6834528a7
commit
e3338ef540
2 changed files with 38 additions and 2 deletions
|
@ -11,8 +11,8 @@ export const DATABASE_PASS = process.env.DATABASE_PASS || "postgres";
|
||||||
export const DATABASE_NAME = process.env.DATABASE_NAME || "postgres";
|
export const DATABASE_NAME = process.env.DATABASE_NAME || "postgres";
|
||||||
|
|
||||||
export const HTTPS = process.env.HTTPS === "true";
|
export const HTTPS = process.env.HTTPS === "true";
|
||||||
export const DOMAIN = process.env.DOMAIN;
|
export const DOMAIN = process.env.DOMAIN || "";
|
||||||
|
|
||||||
if (!DOMAIN) throw "$DOMAIN is empty";
|
if (DOMAIN === "") throw "$DOMAIN is empty";
|
||||||
|
|
||||||
export const BASE_URL = `${HTTPS ? "https" : "http"}://${DOMAIN}`;
|
export const BASE_URL = `${HTTPS ? "https" : "http"}://${DOMAIN}`;
|
||||||
|
|
|
@ -1,9 +1,45 @@
|
||||||
import { RouteOptions } from "fastify";
|
import { RouteOptions } from "fastify";
|
||||||
|
|
||||||
|
import { BASE_URL, DOMAIN } from "~/config.js";
|
||||||
|
import { Account } from "~/db/entities/account.js";
|
||||||
|
import LongmontDataSource from "~/db/index.js";
|
||||||
|
|
||||||
|
interface AuthNode {
|
||||||
|
api_base: string;
|
||||||
|
name_suffix: string;
|
||||||
|
software: {
|
||||||
|
name: string;
|
||||||
|
version: string;
|
||||||
|
source: string;
|
||||||
|
};
|
||||||
|
features: string[];
|
||||||
|
registrations: "open" | "approval" | "closed";
|
||||||
|
usage: {
|
||||||
|
users: number | null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const route: RouteOptions = {
|
const route: RouteOptions = {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
url: "/.well-known/longmont/auth-node",
|
url: "/.well-known/longmont/auth-node",
|
||||||
handler: async (_, res) => {
|
handler: async (_, res) => {
|
||||||
|
const userCount = await LongmontDataSource.getRepository(Account).count();
|
||||||
|
|
||||||
|
res.send({
|
||||||
|
api_base: BASE_URL,
|
||||||
|
name_suffix: DOMAIN,
|
||||||
|
software: {
|
||||||
|
name: "authsrv",
|
||||||
|
version: "0.1.0-dev",
|
||||||
|
source: "https://github.com/longmont-chat",
|
||||||
|
},
|
||||||
|
features: [],
|
||||||
|
registrations: "open",
|
||||||
|
usage: {
|
||||||
|
users: userCount,
|
||||||
|
},
|
||||||
|
} satisfies AuthNode);
|
||||||
|
|
||||||
res.status(204);
|
res.status(204);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue