import fastify from "fastify"; import cors from "@fastify/cors"; import multipart from "@fastify/multipart"; import routes from "./routes"; import { userSchemas } from "./user/user.schema"; import { orgSchemas } from "./organization/organization.schema"; import { tokenSchemas } from "./tokens/token.schema"; import { errorHandler } from "./utils/errors"; import { authorize } from "./auth"; import { permitSchemas } from "./permit/permit.schema"; import { fileSchemas } from "./file/file.schema"; import { oauth } from "./oauth"; import { authRoutes } from "./auth/auth.route"; import { rtsSchemas } from "./rts/rts.schema"; import { taskSchemas } from "./task/task.schema"; import { notificationSchemas } from "./notification/notification.schema"; import { noteSchemas } from "./note/note.schema"; import { webAuthnRoutes } from "./webauthn/webauthn.route"; import { configSchemas } from "./config/config.schema"; import { mailSchemas } from "./mailProxy/mailProxy.schema"; import { viewSchemas } from "./view/view.schema"; import { processedSchemas } from "./processed/processed.schema"; import { cTaskSchemas } from "./ctask/ctask.schema"; import { paymentSchemas } from "./payments/payment.schema"; import { alertSchemas } from "./alert/alert.schema"; import { userConfigSchemas } from "./userConfig/userConfig.schema"; const app = fastify({ logger: true, trustProxy: true }); app.get("/health", (req, res) => { return { status: "OK" }; }); oauth(app); app.decorate("authorize", authorize); app.setErrorHandler(errorHandler); app.register(cors, { origin: [process.env.UI_DOMAIN || "", "http://localhost:8000"], credentials: true, }); app.register(multipart, { limits: { fileSize: 50000000 } }); app.register(authRoutes, { prefix: "/auth" }); app.register(webAuthnRoutes, { prefix: "/webauthn" }); app.register(routes, { prefix: "/api/v1" }); for (const schema of [ ...userSchemas, ...orgSchemas, ...tokenSchemas, ...permitSchemas, ...fileSchemas, ...rtsSchemas, ...taskSchemas, ...cTaskSchemas, ...notificationSchemas, ...noteSchemas, ...configSchemas, ...userConfigSchemas, ...mailSchemas, ...viewSchemas, ...processedSchemas, ...paymentSchemas, ...alertSchemas, ]) { app.addSchema(schema); } export default app;