IO-3151 Package Update and Optimizations
This commit is contained in:
83
server.ts
83
server.ts
@@ -1,4 +1,5 @@
|
||||
import bodyParser from "body-parser";
|
||||
import compression from "compression";
|
||||
import cors from "cors";
|
||||
import dotenv from "dotenv";
|
||||
import express, { Express } from "express";
|
||||
@@ -19,79 +20,82 @@ import { JobsListMedia } from "./jobs/jobsListMedia.js";
|
||||
import { JobsMoveMedia } from "./jobs/jobsMoveMedia.js";
|
||||
import { JobMediaUploadMulter, jobsUploadMedia } from "./jobs/jobsUploadMedia.js";
|
||||
import InitServer, { FolderPaths } from "./util/serverInit.js";
|
||||
import ValidateImsToken from "./util/validateToken.js";
|
||||
import ValidateImsToken from "./util/validateToken.js";
|
||||
|
||||
dotenv.config({
|
||||
path: resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
|
||||
const commonTransportConfig = {
|
||||
maxSize: "20m",
|
||||
maxFiles: 14,
|
||||
tailable: true,
|
||||
zippedArchive: true,
|
||||
format: winston.format.combine(winston.format.timestamp(), winston.format.json()),
|
||||
datePattern: "YYYY-MM-DD"
|
||||
};
|
||||
|
||||
const baseFormat = winston.format.combine(
|
||||
winston.format.timestamp(),
|
||||
winston.format.errors({ stack: true }),
|
||||
winston.format.json(),
|
||||
winston.format.prettyPrint()
|
||||
);
|
||||
|
||||
const consoleTransport = new winston.transports.Console({
|
||||
format: winston.format.combine(winston.format.colorize(), winston.format.timestamp(), winston.format.simple())
|
||||
});
|
||||
|
||||
export const logger = winston.createLogger({
|
||||
format: winston.format.combine(winston.format.timestamp(), winston.format.json(), winston.format.prettyPrint()),
|
||||
format: baseFormat,
|
||||
level: "http",
|
||||
levels: { ...winston.config.syslog.levels, http: 8 },
|
||||
exceptionHandlers: [
|
||||
new DailyRotateFile({
|
||||
filename: path.join(FolderPaths.Root, "logs", "exceptions-%DATE%.log"),
|
||||
datePattern: "YYYY-MM-DD-HH",
|
||||
zippedArchive: true,
|
||||
maxSize: "20m",
|
||||
maxFiles: "14"
|
||||
...commonTransportConfig
|
||||
}),
|
||||
new winston.transports.Console({
|
||||
format: winston.format.combine(winston.format.colorize(), winston.format.simple())
|
||||
})
|
||||
consoleTransport
|
||||
],
|
||||
rejectionHandlers: [
|
||||
new DailyRotateFile({
|
||||
filename: path.join(FolderPaths.Root, "logs", "rejections-%DATE%.log"),
|
||||
datePattern: "YYYY-MM-DD-HH",
|
||||
zippedArchive: true,
|
||||
maxSize: "20m",
|
||||
maxFiles: "14"
|
||||
...commonTransportConfig
|
||||
}),
|
||||
new winston.transports.Console({
|
||||
format: winston.format.combine(winston.format.colorize(), winston.format.simple())
|
||||
})
|
||||
consoleTransport
|
||||
],
|
||||
transports: [
|
||||
new DailyRotateFile({
|
||||
filename: path.join(FolderPaths.Root, "logs", "errors-%DATE%.log"),
|
||||
datePattern: "YYYY-MM-DD-HH",
|
||||
zippedArchive: true,
|
||||
maxSize: "20m",
|
||||
maxFiles: "14",
|
||||
level: "error"
|
||||
level: "error",
|
||||
...commonTransportConfig
|
||||
}),
|
||||
|
||||
new DailyRotateFile({
|
||||
filename: path.join(FolderPaths.Root, "logs", "debug-%DATE%.log"),
|
||||
datePattern: "YYYY-MM-DD-HH",
|
||||
zippedArchive: true,
|
||||
maxSize: "20m",
|
||||
maxFiles: "14",
|
||||
level: "debug"
|
||||
level: "debug",
|
||||
...commonTransportConfig
|
||||
}),
|
||||
new DailyRotateFile({
|
||||
filename: path.join(FolderPaths.Root, "logs", "ALL-%DATE%.log"),
|
||||
datePattern: "YYYY-MM-DD-HH",
|
||||
zippedArchive: true,
|
||||
maxSize: "20m",
|
||||
maxFiles: "14"
|
||||
...commonTransportConfig
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
logger.add(
|
||||
new winston.transports.Console({
|
||||
format: winston.format.combine(winston.format.colorize(), winston.format.simple())
|
||||
})
|
||||
);
|
||||
}
|
||||
logger.add(
|
||||
new winston.transports.Console({
|
||||
format: winston.format.combine(winston.format.colorize(), winston.format.timestamp(), winston.format.simple())
|
||||
})
|
||||
);
|
||||
|
||||
const app: Express = express();
|
||||
const port = process.env.PORT;
|
||||
app.set("etag", false);
|
||||
app.use(compression());
|
||||
app.use((req, res, next) => {
|
||||
res.setHeader("Connection", "keep-alive");
|
||||
next();
|
||||
});
|
||||
app.use(nocache());
|
||||
app.use(bodyParser.json({ limit: "1000mb" }));
|
||||
app.use(bodyParser.urlencoded({ limit: "1000mb", extended: true }));
|
||||
@@ -135,6 +139,9 @@ app.post(
|
||||
app.get("/", ValidateImsToken, (req: express.Request, res: express.Response) => {
|
||||
res.send("IMS running.");
|
||||
});
|
||||
app.get("/health", (req: express.Request, res: express.Response) => {
|
||||
res.status(200).send("OK");
|
||||
});
|
||||
|
||||
InitServer();
|
||||
app.use(FolderPaths.StaticPath, express.static(FolderPaths.Root, { etag: false, maxAge: 30 * 1000 }));
|
||||
|
||||
Reference in New Issue
Block a user