Setup test, break apart entrypoint, & align GHA workflow

This commit is contained in:
Reginald Bondoc
2022-12-20 00:56:53 +01:00
parent 33dddd440c
commit fc906e7dc7
15 changed files with 748 additions and 303 deletions
+32
View File
@@ -0,0 +1,32 @@
/* eslint-disable no-console */
import mongoose from 'mongoose';
import { createTerminus } from '@godaddy/terminus';
export const setUpHealthEndpoint = <T>(server: T) => {
const onSignal = () => {
console.log('Server is starting clean-up');
return Promise.all([
() => {
if (mongoose.connection && mongoose.connection.readyState == 1) {
mongoose.connection.close();
() => {
console.info('Database connection closed');
};
}
}
]);
};
const healthCheck = () => {
// `state.isShuttingDown` (boolean) shows whether the server is shutting down or not
// optionally include a resolve value to be included as info in the health check response
return Promise.resolve();
};
createTerminus(server, {
healthChecks: {
'/healthcheck': healthCheck,
onSignal
}
});
};