Skip to content

Commit

Permalink
u work on this abrar
Browse files Browse the repository at this point in the history
  • Loading branch information
LordFarquaadtheCreator committed Jun 21, 2024
1 parent 1c72f70 commit 384c1a3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
25 changes: 13 additions & 12 deletions db.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import client from './db.config';
import checkDB from 'dbChecker';

let isActive = false;
const getDB = async () => {
console.log("Connecting to Database ...");

if(client.connected){
try {
await client.connect();
console.log("Database connected");
return client;
} catch (err: any) {
throw Error("Client Not Found");
}
}
return client;
if (isActive) {
console.log("Database already connected");
return client;
}
try {
await client.connect();
console.log("Database connected");
isActive = true;
return client;
} catch (err: any) {
return client;
}
}

export default getDB;
3 changes: 3 additions & 0 deletions dbCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ runWithTimeout(getDB, parseInt(process.argv[2]), parseInt(process.argv[2]))
console.error(error);
process.exit(1);
});


export default runWithTimeout;
10 changes: 5 additions & 5 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import http from 'http';
import https from 'https';
import fs from 'fs';

const privateKey = fs.readFileSync('cert/privkey.pem', 'utf8');
const certificate = fs.readFileSync('cert/cert.pem', 'utf8');
const credentials = {key: privateKey, cert: certificate};
// const privateKey = fs.readFileSync('cert/privkey.pem', 'utf8');
// const certificate = fs.readFileSync('cert/cert.pem', 'utf8');
// const credentials = {key: privateKey, cert: certificate};

const PORT = 3000;
const INTERVAL = secondsToMs(60 * 60); // 1 hr
Expand Down Expand Up @@ -67,7 +67,7 @@ app.get("*", (req: any, res: any) => {
});

const httpServer = http.createServer(app);
const httpsServer = https.createServer(credentials, app);
// const httpsServer = https.createServer(credentials, app);

httpServer.listen(PORT);
httpsServer.listen(PORT+1);
// httpsServer.listen(PORT+1);

0 comments on commit 384c1a3

Please sign in to comment.