Initial Commit
This commit is contained in:
31
src/index.ts
Normal file
31
src/index.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
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);
|
||||
});
|
||||
Reference in New Issue
Block a user