eris/api/serveApi.ts

35 lines
1.0 KiB
TypeScript
Raw Permalink Normal View History

2023-10-13 19:18:19 +00:00
import {
createEndpoint,
createLoggerMiddleware,
createMethodFilter,
createPathFilter,
} from "t_rest/server";
2023-10-05 09:00:51 +00:00
import { jobsRoute } from "./jobsRoute.ts";
2023-10-09 19:03:31 +00:00
import { paramsRoute } from "./paramsRoute.ts";
2023-10-05 09:00:51 +00:00
import { sessionsRoute } from "./sessionsRoute.ts";
2023-10-09 19:03:31 +00:00
import { statsRoute } from "./statsRoute.ts";
2023-10-05 09:00:51 +00:00
import { usersRoute } from "./usersRoute.ts";
2023-10-11 01:59:52 +00:00
import { workersRoute } from "./workersRoute.ts";
2023-10-13 19:18:19 +00:00
import { bot } from "../bot/mod.ts";
2023-10-05 09:00:51 +00:00
2023-10-09 19:03:31 +00:00
export const serveApi = createLoggerMiddleware(
createPathFilter({
"jobs": jobsRoute,
"sessions": sessionsRoute,
"users": usersRoute,
"settings/params": paramsRoute,
"stats": statsRoute,
2023-10-11 01:59:52 +00:00
"workers": workersRoute,
2023-10-13 19:18:19 +00:00
"bot": createMethodFilter({
// deno-lint-ignore require-await
GET: createEndpoint({ query: null, body: null }, async () => {
const username = bot.botInfo.username;
return { status: 200, body: { type: "application/json", data: { username } } };
}),
}),
2023-10-09 19:03:31 +00:00
}),
{ filterStatus: (status) => status >= 400 },
);
2023-10-05 09:00:51 +00:00
2023-10-08 21:23:54 +00:00
export type ApiHandler = typeof serveApi;