From e2a88e6065988a637c6ac541ff4abf0181503f4f Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 6 May 2021 18:51:30 +0200 Subject: server: Save rotating HTTP access log. --- .gitignore | 1 + package.json | 2 ++ server.js | 11 ++++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index e114d7f..078a51e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ package-lock.json node_modules db sessions +log .env *.pem vassal diff --git a/package.json b/package.json index 93c4049..431f609 100644 --- a/package.json +++ b/package.json @@ -11,9 +11,11 @@ "ejs": "^3.1.5", "express": "^4.17.1", "express-session": "^1.17.1", + "morgan": "^1.10.0", "passport": "^0.4.1", "passport-local": "^1.0.0", "passport.socketio": "^3.7.0", + "rotating-file-stream": "^2.1.5", "socket.io": "^3.0.4" } } diff --git a/server.js b/server.js index f980f49..c01f711 100644 --- a/server.js +++ b/server.js @@ -18,7 +18,7 @@ const SESSION_SECRET = "Caesar has a big head!"; const MAX_OPEN_GAMES = 3; -let sessionStore = new SQLiteStore(); +let session_store = new SQLiteStore(); let db = new sqlite3(process.env.DATABASE || "./db"); let app = express(); let http_port = process.env.PORT || 8080; @@ -36,6 +36,11 @@ let io = { on: function (ev,fn) { io1.on(ev,fn); io2.on(ev,fn); }, }; +const morgan = require('morgan'); +const rfs = require('rotating-file-stream'); +const log_file = rfs.createStream('access.log', { interval: '1d', path: 'log' }); +app.use(morgan('combined', {stream: log_file})); + app.disable('etag'); app.set('view engine', 'ejs'); app.use(body_parser.urlencoded({extended:false})); @@ -43,7 +48,7 @@ app.use(express_session({ secret: SESSION_SECRET, resave: false, saveUninitialized: true, - store: sessionStore, + store: session_store, cookie: { maxAge: 7 * 24 * 60 * 60 * 1000 } })); app.use(connect_flash()); @@ -51,7 +56,7 @@ app.use(connect_flash()); io.use(passport_socket.authorize({ key: 'connect.sid', secret: SESSION_SECRET, - store: sessionStore, + store: session_store, })); const is_immutable = /\.(svg|png|jpg|jpeg|woff2)$/; -- cgit v1.2.3