Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as http from 'http';
import app from './app';
import { version } from './package.json';
import ErrnoException = NodeJS.ErrnoException;
import checkDatabaseConnection from './utils/prisma';

// Initialise globals
global.config = config;
Expand All @@ -26,6 +27,11 @@ server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Checks if DB is connected
*/
void checkDatabaseConnection();

/**
* Event listener for HTTP server "error" event.
*/
Expand Down
15 changes: 15 additions & 0 deletions utils/prisma.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import prisma from '../prisma/prisma';

async function checkDatabaseConnection(): Promise<void> {
try {
await prisma.$connect();
logger.error('Database connected.');
} catch (error) {
logger.error('Database connection failed:', error);
process.exit(1);
} finally {
await prisma.$disconnect();
}
}

export default checkDatabaseConnection;