From ea4c8007026d39ce46ff38f948d39b093c3bcb8d Mon Sep 17 00:00:00 2001 From: Danilo Hoffmann Date: Fri, 7 Feb 2020 15:39:46 +0100 Subject: [PATCH] feat: use morgan for logging in expressjs server --- package-lock.json | 30 ++++++++++++++++++++++++++++-- package.json | 1 + server.ts | 8 ++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9d5cb965b5..fe17c046a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7113,6 +7113,21 @@ "integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==", "dev": true }, + "basic-auth": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz", + "integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==", + "requires": { + "safe-buffer": "5.1.2" + }, + "dependencies": { + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + } + } + }, "batch": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/batch/-/batch-0.6.1.tgz", @@ -15022,6 +15037,18 @@ "resolved": "https://registry.npmjs.org/modify-values/-/modify-values-1.0.1.tgz", "integrity": "sha512-xV2bxeN6F7oYjZWTe/YPAy6MN2M+sL4u/Rlm2AHCIVGfo2p1yGmBHQ6vHehl4bRTZBdHu3TSkWdYgkwpYzAGSw==" }, + "morgan": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz", + "integrity": "sha512-HQStPIV4y3afTiCYVxirakhlCfGkI161c76kKFca7Fk1JusM//Qeo1ej2XaMniiNeaZklMVrh3vTtIzpzwbpmA==", + "requires": { + "basic-auth": "~2.0.0", + "debug": "2.6.9", + "depd": "~1.1.2", + "on-finished": "~2.3.0", + "on-headers": "~1.0.1" + } + }, "move-concurrently": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz", @@ -15622,8 +15649,7 @@ "on-headers": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz", - "integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==", - "dev": true + "integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==" }, "once": { "version": "1.4.0", diff --git a/package.json b/package.json index 56202db930..d8d0c72ab4 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,7 @@ "express": "^4.17.1", "express-robots-txt": "0.4.1", "lodash-es": "^4.17.15", + "morgan": "^1.9.1", "ng-recaptcha": "^5.0.0", "ng2-validation": "^4.2.0", "ngx-infinite-scroll": "^8.0.1", diff --git a/server.ts b/server.ts index 46df7b9c74..9a45732c99 100644 --- a/server.ts +++ b/server.ts @@ -46,6 +46,14 @@ app.engine( app.set('view engine', 'html'); app.set('views', join(DIST_FOLDER, 'browser')); +if (logging) { + app.use( + require('morgan')('tiny', { + skip: req => req.originalUrl.startsWith('/INTERSHOP/static'), + }) + ); +} + // seo robots.txt const pathToRobotsTxt = join(DIST_FOLDER, 'robots.txt'); if (fs.existsSync(pathToRobotsTxt)) {