Files
permit-api/src/index.ts
2024-12-19 13:54:15 +05:30

32 lines
784 B
TypeScript

import mongoose from "mongoose";
import fastify from "fastify";
import routes from "./routes";
import { userSchemas } from "./user/user.schema";
import { orgSchemas } from "./organization/organization.schema";
import { errorHandler } from "./utils/errors";
const app = fastify({ logger: true });
app.get("/health", (req, res) => {
return { status: "OK" };
});
app.register(routes, { prefix: "/api/v1" });
app.setErrorHandler(errorHandler);
(async () => {
const PORT = parseInt(process.env.PORT ?? "8000");
const DB_URI = process.env.DB_URI ?? "";
for (const schema of [...userSchemas, ...orgSchemas]) {
app.addSchema(schema);
}
await mongoose.connect(DB_URI);
await app.listen({ port: PORT });
})().catch((err) => {
console.log(err);
process.exit(1);
});