Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function onSignal() {
console.log('server is starting cleanup');
return Promise.all([
// add any clean-up logic
]);
}
function onShutdown () {
console.log('cleanup finished, server is shutting down');
}
function onHealthCheck() {
return Promise.resolve();
}
createTerminus(server, {
signals: ['SIGHUP','SIGINT','SIGTERM'],
healthChecks: {
'/health': onHealthCheck,
'/': onHealthCheck
},
onSignal,
onShutdown
});
server.listen(port, () => {
console.log(`Listening on port ${port}`);
});
module.exports = server;
import api from "./api";
import config from "./config.json";
import tracer from "./middleware/tracer";
import terminusOptions from "./utils/health";
import envVariables from "./envVariables";
import "./kafka/consumer";
var swaggerUi = require("swagger-ui-express"),
swaggerDocument = require("./swagger.json");
const { createTerminus } = require("@godaddy/terminus");
let app = express();
app.server = http.createServer(app);
// Enable health checks and kubernetes shutdown hooks
createTerminus(app.server, terminusOptions);
// logger
app.use(morgan("dev"));
// 3rd party middleware
app.use(
cors({
exposedHeaders: config.corsHeaders
})
);
app.use(
bodyParser.json({
limit: config.bodyLimit
})
);
'use strict'
const http = require('http')
const { createTerminus } = require('@godaddy/terminus')
const app = require('./lib/app')
const port = app.get('port')
const logger = app.get('logger')
const healthCheck = app.get('healthCheck')
const periodSeconds = app.get('periodSeconds')
const io = app.get('io')()
// create server
const server = http.createServer(app)
io.attach(server)
createTerminus(server, {
healthChecks: {
'/healthz': healthCheck
},
beforeShutdown,
onSignal,
onShutdown,
logger: (...args) => logger.error(...args)
})
server.listen(port, () => {
logger.info(`Server listening on port ${port}`)
})
async function onSignal () {
logger.debug('Server is starting cleanup')
try {
await new Promise(resolve => io.close(resolve))
httpServer.listen(PORT, () => {
createTerminus(httpServer, {
signal: 'SIGINT',
timeout: 1000,
onSignal,
onShutdown
});
logger.info(
`[API] Bootstrap > ready on http://localhost:${PORT}${server.graphqlPath}, base path ${nconf.get(
'app:base_path'
)}`
);
logger.info(
`[API] Bootstrap > Health check available at: http://localhost:${PORT}/.well-known/apollo/server-health`
);
if (isAppRealTime) {
logger.info(`[API] Bootstrap > WebSocket ready at ws://localhost:${PORT}${server.subscriptionsPath}`);
} else {
httpServer.listen(PORT, () => {
createTerminus(httpServer, {
signal: 'SIGINT',
timeout: 1000,
onSignal,
onShutdown
});
logger.info(`🚀 Api ready on http://domain:${PORT}${server.graphqlPath}`);
if (isAppRealTime) {
logger.info(
`🚀 WebSocket ready at ws://domain:${PORT}${server.subscriptionsPath}`
);
} else {
logger.info(`🚀 WebSocket deactivated, config your redis and activate it`);
}
});