Skip to content

Commit

Permalink
initializeDB out of constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
jipsonminibhavan committed Feb 8, 2024
1 parent 34c38c4 commit 5b067b1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
10 changes: 9 additions & 1 deletion backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ import linkRoutes from "./routes/linkRoutes";

const app = new App([userRoutes, statusRoutes, linkRoutes]);

app.listen();
app
.initializeDB()
.then(() => {
app.listen();
})
.catch((error) => {
console.error("Failed to initialize the application:", error);
process.exit(1);
});

// import express, { Request, Response } from "express";
// import bodyParser from "body-parser";
Expand Down
3 changes: 1 addition & 2 deletions backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class App {
this.initializeMiddleware();
this.initializePassport();
this.initializeRoutes(routes);
this.initializeDB();
}
private initializeMiddleware(): void {
this.app.use(cors());
Expand Down Expand Up @@ -48,7 +47,7 @@ class App {
});
}

private async initializeDB(): Promise<void> {
public async initializeDB(): Promise<void> {
try {
await connectToDB();
console.log("Database connection successful");
Expand Down
3 changes: 1 addition & 2 deletions resolver/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class App {
this.express = express();
this.middleware();
this.initializeRouters(routers);
this.databaseConnection();
}

private middleware(): void {
Expand All @@ -24,7 +23,7 @@ class App {
});
}

private async databaseConnection(): Promise<void> {
public async initializeDB(): Promise<void> {
try {
await connectToDB();
} catch (error) {
Expand Down
10 changes: 9 additions & 1 deletion resolver/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ import linkRoutes from "./routes/linkRoutes";

const app = new App([linkRoutes]);

app.listen();
app
.initializeDB()
.then(() => {
app.listen();
})
.catch((error) => {
console.error("Failed to initialize the application:", error);
process.exit(1);
});

0 comments on commit 5b067b1

Please sign in to comment.