diff --git a/src/server/Server.ts b/src/server/Server.ts index 4ca77b1..710f23a 100644 --- a/src/server/Server.ts +++ b/src/server/Server.ts @@ -22,12 +22,12 @@ export class Server { private initialize(): void { this.app = express(); this.httpServer = createServer(this.app); - this.mysqlConnection = mysql.createConnection({ - host: process.env.MYSQL_HOST || "localhost", - user: process.env.MYSQL_USER || "root", - password: process.env.MYSQL_PASSWORD || "", - database: process.env.MYSQL_DATABASE || "hochzeit" - }); + // this.mysqlConnection = mysql.createConnection({ + // host: process.env.MYSQL_HOST || "localhost", + // user: process.env.MYSQL_USER || "root", + // password: process.env.MYSQL_PASSWORD || "", + // database: process.env.MYSQL_DATABASE || "hochzeit" + // }); this.configureApp(); this.configureRoutes(); @@ -36,8 +36,29 @@ export class Server { private async query(sql): Promise { return new Promise((resolve, reject) => { + try { + + if (!this.mysqlConnection || this.mysqlConnection.state === "disconnected"){ + console.log("reopening connection..."); + this.mysqlConnection = mysql.createConnection({ + host: process.env.MYSQL_HOST || "localhost", + user: process.env.MYSQL_USER || "root", + password: process.env.MYSQL_PASSWORD || "", + database: process.env.MYSQL_DATABASE || "hochzeit" + }); + + // setTimeout(() => { + // this.mysqlConnection.destroy(); + // }, 5000); + } + }catch(e){ + console.error(e); + reject(e); + } + this.mysqlConnection.query(sql, (error, results) => { if (error) { + console.error(error); reject(error) } else { resolve(results); @@ -84,4 +105,4 @@ export class Server { callback(this.DEFAULT_PORT); }); } -} \ No newline at end of file +}