mirror of
https://github.com/ahmadk953/poixpixel-discord-bot.git
synced 2025-05-10 02:33:06 +00:00
chore: added TLS error handling to database and cache
This commit is contained in:
parent
7fd9497fb8
commit
4def8df3fe
4 changed files with 47 additions and 16 deletions
|
@ -11,10 +11,20 @@ export default defineConfig({
|
||||||
dialect: 'postgresql',
|
dialect: 'postgresql',
|
||||||
dbCredentials: {
|
dbCredentials: {
|
||||||
url: database.dbConnectionString,
|
url: database.dbConnectionString,
|
||||||
ssl: {
|
ssl: (() => {
|
||||||
|
try {
|
||||||
|
return {
|
||||||
ca: fs.readFileSync(path.resolve('./certs/psql-ca.crt')),
|
ca: fs.readFileSync(path.resolve('./certs/psql-ca.crt')),
|
||||||
cert: fs.readFileSync(path.resolve('./certs/psql-server.crt')),
|
|
||||||
key: fs.readFileSync(path.resolve('./certs/psql-client.key')),
|
key: fs.readFileSync(path.resolve('./certs/psql-client.key')),
|
||||||
},
|
cert: fs.readFileSync(path.resolve('./certs/psql-server.crt')),
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(
|
||||||
|
'Failed to load certificates for database, using insecure connection:',
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
})(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
16
src/db/db.ts
16
src/db/db.ts
|
@ -100,11 +100,21 @@ export async function initializeDatabaseConnection(): Promise<boolean> {
|
||||||
// Create new connection pool
|
// Create new connection pool
|
||||||
dbPool = new Pool({
|
dbPool = new Pool({
|
||||||
connectionString: config.database.dbConnectionString,
|
connectionString: config.database.dbConnectionString,
|
||||||
ssl: {
|
ssl: (() => {
|
||||||
|
try {
|
||||||
|
return {
|
||||||
ca: fs.readFileSync(path.resolve('./certs/psql-ca.crt')),
|
ca: fs.readFileSync(path.resolve('./certs/psql-ca.crt')),
|
||||||
cert: fs.readFileSync(path.resolve('./certs/psql-server.crt')),
|
|
||||||
key: fs.readFileSync(path.resolve('./certs/psql-client.key')),
|
key: fs.readFileSync(path.resolve('./certs/psql-client.key')),
|
||||||
},
|
cert: fs.readFileSync(path.resolve('./certs/psql-server.crt')),
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(
|
||||||
|
'Failed to load certificates for database, using insecure connection:',
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
})(),
|
||||||
connectionTimeoutMillis: 10000,
|
connectionTimeoutMillis: 10000,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -93,11 +93,21 @@ async function initializeRedisConnection() {
|
||||||
},
|
},
|
||||||
maxRetriesPerRequest: 3,
|
maxRetriesPerRequest: 3,
|
||||||
enableOfflineQueue: true,
|
enableOfflineQueue: true,
|
||||||
tls: {
|
tls: (() => {
|
||||||
|
try {
|
||||||
|
return {
|
||||||
ca: fs.readFileSync(path.resolve('./certs/cache-ca.crt')),
|
ca: fs.readFileSync(path.resolve('./certs/cache-ca.crt')),
|
||||||
cert: fs.readFileSync(path.resolve('./certs/cache-server.crt')),
|
|
||||||
key: fs.readFileSync(path.resolve('./certs/cache-client.key')),
|
key: fs.readFileSync(path.resolve('./certs/cache-client.key')),
|
||||||
},
|
cert: fs.readFileSync(path.resolve('./certs/cache-server.crt')),
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(
|
||||||
|
'Failed to load certificates for cache, using insecure connection:',
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
})(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// ========================
|
// ========================
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import Canvas from '@napi-rs/canvas';
|
import Canvas from '@napi-rs/canvas';
|
||||||
import path from 'path';
|
import fs from 'node:fs';
|
||||||
|
import path from 'node:path';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
AttachmentBuilder,
|
AttachmentBuilder,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue