Skip to content

Commit

Permalink
adding initial db check to bypass having to wait INTERVAL on intial load
Browse files Browse the repository at this point in the history
  • Loading branch information
LordFarquaadtheCreator committed Jun 12, 2024
1 parent e3429be commit 161154f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ const TIMEOUT = secondsToMs(10);
const app = express();
let dbAval: boolean = true;

// initial check
try{
console.log(`Please wait ${TIMEOUT/1000}s for the database to connect`)
dbAval = await checkDB(TIMEOUT);
} catch (e: any) {
dbAval = false;
}

// routine
setInterval(async () => {
try {
dbAval = await checkDB(TIMEOUT);
Expand All @@ -27,7 +36,10 @@ setInterval(async () => {
logger.info(`Database is ${dbAval ? "available" : "not available"}`);
}, INTERVAL);

app.use(cors());
// app.use(cors( // TODO: do this correctly
// "byteccny",
// "localhost:3000";
// ));
app.use((req: any, res: any, next: any) => {
logger.info(`Received a ${req.method} request for ${req.url}`);
next();
Expand Down

0 comments on commit 161154f

Please sign in to comment.