mirror of
https://github.com/20kaushik02/express-sequelize-backend-template.git
synced 2025-12-06 06:34:06 +00:00
overall: formatting check, jsdoc type hints, express res/return stuff utils - changes in logger, dateformatter and removed unneeded ones .env file changes license check, readme update package.json update - version, deps, URLs server cleanup sequelize config check
57 lines
1.2 KiB
JavaScript
57 lines
1.2 KiB
JavaScript
require("dotenv-flow").config();
|
|
|
|
const util = require('util');
|
|
const express = require("express");
|
|
|
|
const cors = require("cors");
|
|
const helmet = require("helmet");
|
|
|
|
const logger = require("./utils/logger")(module);
|
|
|
|
const app = express();
|
|
|
|
// Enable this if you run behind a proxy (e.g. nginx)
|
|
app.set('trust proxy', process.env.TRUST_PROXY);
|
|
|
|
app.use(cors());
|
|
app.use(helmet());
|
|
app.disable("x-powered-by");
|
|
|
|
app.use(express.json());
|
|
app.use(express.urlencoded({ extended: true }));
|
|
|
|
// Static
|
|
app.use(express.static(__dirname + '/static'));
|
|
|
|
// Put routes here
|
|
|
|
// Fallbacks
|
|
app.use((req, res) => {
|
|
res.status(200).send("Back-end for");
|
|
logger.info("Unrecognized URL", { url: req.url });
|
|
return;
|
|
});
|
|
|
|
const port = process.env.PORT || 5000;
|
|
|
|
app.listen(port, () => {
|
|
logger.info(`App Listening on port ${port}`);
|
|
});
|
|
|
|
const cleanupFunc = (signal) => {
|
|
if (signal)
|
|
logger.info(`${signal} signal received, shutting down now...`);
|
|
|
|
Promise.allSettled([
|
|
// handle DB conn, sockets, etc. here
|
|
util.promisify(server.close),
|
|
]).then(() => {
|
|
logger.info("Cleaned up, exiting.");
|
|
process.exit(0);
|
|
});
|
|
}
|
|
|
|
['SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGTERM', 'SIGUSR1', 'SIGUSR2'].forEach((signal) => {
|
|
process.on(signal, () => cleanupFunc(signal));
|
|
});
|