Skip to content

Commit 3a149c5

Browse files
update SSL variables
1 parent 30f0745 commit 3a149c5

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

server/controllers/mysqlData.controller.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ const dotenv = require('dotenv');
55
dotenv.config();
66

77
const mySQLdataController = {};
8+
const SSL_KEY =
9+
Buffer.from(process.env.SSL_KEY, 'base64').toString('ascii') ||
10+
fs.readFileSync('./.cert/key.pem').toString();
11+
const SSL_CERT =
12+
Buffer.from(process.env.SSL_CERT, 'base64').toString('ascii') ||
13+
fs.readFileSync('./.cert/cert.pem').toString();
814

915
/**
1016
* mySQLdataController.getSchema
@@ -28,14 +34,9 @@ export const getSchema = async (req, res, next) => {
2834
port,
2935
user: username,
3036
database: database_name,
31-
// Add SSL certification to avoid security issue.
3237
ssl: {
33-
key:
34-
fs.readFileSync('./.cert/key.pem').toString() ||
35-
Buffer.from(process.env.SSL_KEY, 'base64').toString('ascii'),
36-
cert:
37-
fs.readFileSync('./.cert/cert.pem').toString() ||
38-
Buffer.from(process.env.SSL_CERT, 'base64').toString('ascii'),
38+
key: SSL_KEY,
39+
cert: SSL_CERT,
3940
},
4041
},
4142
dumpToFile: '../db_schemas',

server/models/userModel.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ const dotenv = require('dotenv');
66
dotenv.config();
77

88
const { USER_DB_USER, USER_DB_PW } = process.env;
9-
const SSL_KEY = process.env.SSL_KEY as string;
10-
const SSL_CERT = process.env.SSL_CERT as string;
9+
const SSL_KEY =
10+
(process.env.SSL_KEY as string) || fs.readFileSync('./.cert/key.pem').toString();
11+
const SSL_CERT =
12+
(process.env.SSL_CERT as string) || fs.readFileSync('./.cert/cert.pem').toString();
1113

1214
const pool = mysql
1315
.createPool({
@@ -17,12 +19,8 @@ const pool = mysql
1719
password: USER_DB_PW,
1820
database: 'dbspy_4',
1921
ssl: {
20-
key:
21-
fs.readFileSync('./.cert/key.pem').toString() ||
22-
Buffer.from(SSL_KEY, 'base64').toString('ascii'),
23-
cert:
24-
fs.readFileSync('./.cert/cert.pem').toString() ||
25-
Buffer.from(SSL_CERT, 'base64').toString('ascii'),
22+
key: SSL_KEY,
23+
cert: SSL_CERT,
2624
},
2725
})
2826
.promise(); // wrap with promise API

0 commit comments

Comments
 (0)