diff --git a/app.ts b/app.ts index 60a7002..7ea5edd 100644 --- a/app.ts +++ b/app.ts @@ -1,6 +1,7 @@ import express from "express"; import path from 'path' import morgan from 'morgan' +import 'dotenv/config' const hostname = '127.0.0.1'; const httpPort = 4080; diff --git a/miscellaneous/db.ts b/miscellaneous/db.ts index 6bdd9cd..667eb2b 100644 --- a/miscellaneous/db.ts +++ b/miscellaneous/db.ts @@ -1,11 +1,34 @@ -import mysql from 'mysql2/promise' +import mysql, { type PoolOptions } from 'mysql2/promise' -const pool = mysql.createPool({ - host: '192.168.0.11', - port: 3306, - user: 'myUsage', - password: 'vEj8lFj22srB_(VG', - database: 'my_general_db' -}); +const poolOptions: PoolOptions = { + host: "", + port: 0, + user: "", + password: "", + database: "" +} + +if (process.env.DBIP) { + poolOptions.host = process.env.DBIP; +} + +if (process.env.DBPort) { + poolOptions.port = parseInt(process.env.DBPort); +} + +if (process.env.DBUser) { + poolOptions.user = process.env.DBUser; +} + +if (process.env.DBPassword) { + poolOptions.password = process.env.DBPassword; +} + +if (process.env.DBDatabase) { + poolOptions.database = process.env.DBDatabase; +} + + +const pool = mysql.createPool(poolOptions); export default pool; \ No newline at end of file diff --git a/package.json b/package.json index ff61ff6..6c6e5b5 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "dependencies": { "@types/express": "^4.17.21", "@types/morgan": "^1.9.9", + "dotenv": "^16.4.5", "express": "^4.18.2", "hbs": "^4.2.0", "morgan": "~1.9.1", diff --git a/templ.env b/templ.env new file mode 100644 index 0000000..a6e9732 --- /dev/null +++ b/templ.env @@ -0,0 +1,5 @@ +DBIP= +DBPort= +DBUser= +DBPassword= +DBDatabase= \ No newline at end of file