Added token authentication, organization module. Moved server bootstrapping code to server.ts file

This commit is contained in:
2024-12-19 21:49:54 +05:30
parent 970a972b11
commit 4b49c43a0c
16 changed files with 652 additions and 22 deletions

31
src/server.ts Normal file
View 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 { tokenSchemas } from "./tokens/token.schema";
import { errorHandler } from "./utils/errors";
import { AuthenticatedUser, authHandler } from "./auth";
declare module "fastify" {
export interface FastifyRequest {
user: AuthenticatedUser;
}
}
const app = fastify({ logger: true });
app.get("/health", (req, res) => {
return { status: "OK" };
});
app.register(routes, { prefix: "/api/v1" });
app.setErrorHandler(errorHandler);
app.addHook("onRequest", authHandler);
for (const schema of [...userSchemas, ...orgSchemas, ...tokenSchemas]) {
app.addSchema(schema);
}
export default app;