Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as bodyParser from "body-parser";
import * as express from "express";
import * as logger from "morgan";
import * as path from "path";
import rfs from "rotating-file-stream";
import route from "./server/routes";
// Set up the express app
const app = express();
// Log requests to the console.
app.use(logger("dev"));
// create a rotating write stream
const accessLogStream = rfs("access.log", {
interval: "1d", // rotate daily
path: path.join(__dirname, "log")
});
// setup the logger
app.use(logger("combined", { stream: accessLogStream }));
// Parse incoming requests data (https://github.com/expressjs/body-parser)
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
const cors = require("cors");
app.use(cors());
// Setup a default catch-all route that sends back a welcome message in JSON format.
route(app);
import api from './api';
import { sequelize } from './models/db';
import { Team, User } from './models';
fetch.promise = Promise;
const app = express();
const logDirectory = path.join(__dirname, 'log');
// ensure log directory exists
// eslint-disable-next-line no-unused-expressions
fs.existsSync(logDirectory) || fs.mkdirSync(logDirectory);
// create a rotating write stream
const accessLogStream = rfs('access.log', {
interval: '1d', // rotate daily
path: logDirectory
});
export const wsServer = new HttpServer(app);
//
// Tell any CSS tooling (such as Material UI) to use all vendor prefixes if the
// user agent is not known.
// -----------------------------------------------------------------------------
global.navigator = global.navigator || {};
global.navigator.userAgent = global.navigator.userAgent || 'all';
//
// Register Node.js middleware
// -----------------------------------------------------------------------------
private getFileStream(): WriteStream {
const createFileName = (time: Date, index: number) => {
if (!time) {
return `${app.getName()}-current.log`;
}
let filename = time.toISOString().slice(0, 10);
if (index > 1) {
filename += `.${index}`;
}
return `${app.getName()}-${filename}.log.gz`;
};
return rfs(createFileName, {
path: process.env.CORE_PATH_LOG,
initialRotation: true,
interval: this.options.fileRotator ? this.options.fileRotator.interval : "1d",
maxSize: "100M",
maxFiles: 10,
compress: "gzip",
});
}
}
enableFileLogging() {
if (this.logWriter) {
return;
}
this.logWriter = rfs.createStream(Logger.logFileGenerator, {
size: '10M',
interval: '1d',
path: store.getLogDir(),
});
}