Added token authentication, organization module. Moved server bootstrapping code to server.ts file
This commit is contained in:
31
src/server.ts
Normal file
31
src/server.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 { 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;
|
||||
Reference in New Issue
Block a user