From 88fa2a1071e76964c1ed97f9443279352068afc6 Mon Sep 17 00:00:00 2001 From: Jack Wu Date: Mon, 20 Feb 2023 11:45:40 +0000 Subject: [PATCH] added logger --- server/server.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/server.js b/server/server.js index de83890..277bb6e 100644 --- a/server/server.js +++ b/server/server.js @@ -2,12 +2,17 @@ const fs = require('fs'); const path = require("path"); const readline = require("readline"); const express = require("express"); -const session = require('express-session') -const MemoryStore = require('memorystore')(session) +const morgan = require('morgan'); +const session = require('express-session'); +const MemoryStore = require('memorystore')(session); const { Document } = require("flexsearch"); const app = express(); +morgan.token('body', (req, res) => JSON.stringify(req.body)); +app.use(morgan(':remote-addr :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent" ":body"', { + stream: fs.createWriteStream('./access.log', {flags: 'a'}) +})); app.use(express.static(path.join(__dirname, '../client/public'))); app.use(express.json()); //app.use(express.urlencoded({extended: false}));