Skip to content

Commit c238e82

Browse files
add readFileSync for SSL data
1 parent 7105ba8 commit c238e82

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

server/controllers/mysqlData.controller.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ export const getSchema = async (req, res, next) => {
3030
database: database_name,
3131
// Add SSL certification to avoid security issue.
3232
ssl: {
33-
key: Buffer.from(process.env.SSL_KEY, 'base64').toString('ascii'),
34-
cert: Buffer.from(process.env.SSL_CERT, 'base64').toString('ascii'),
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'),
3539
},
3640
},
3741
dumpToFile: '../db_schemas',

server/models/userModel.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import mysql from 'mysql2';
2+
import fs from 'fs';
23
import log from '../logger';
34

45
const dotenv = require('dotenv');
@@ -16,8 +17,12 @@ const pool = mysql
1617
password: USER_DB_PW,
1718
database: 'dbspy_4',
1819
ssl: {
19-
key: Buffer.from(SSL_KEY, 'base64').toString('ascii'),
20-
cert: Buffer.from(SSL_CERT, 'base64').toString('ascii'),
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'),
2126
},
2227
})
2328
.promise(); // wrap with promise API

0 commit comments

Comments
 (0)