From 103a89bc9833945d7fb0edb99516dbcd12372c01 Mon Sep 17 00:00:00 2001 From: PJ Date: Wed, 22 Jan 2020 19:55:16 +0100 Subject: [PATCH] Improve logging --- packages/siaviewnode-server/.gitignore | 2 + packages/siaviewnode-server/package-lock.json | 498 ++++++++++++++++++ packages/siaviewnode-server/package.json | 12 +- packages/siaviewnode-server/src/access.log | 0 packages/siaviewnode-server/src/logger.ts | 18 + packages/siaviewnode-server/src/main.ts | 178 +++---- packages/siaviewnode-server/tsconfig.json | 24 +- 7 files changed, 633 insertions(+), 99 deletions(-) create mode 100644 packages/siaviewnode-server/package-lock.json create mode 100644 packages/siaviewnode-server/src/access.log create mode 100644 packages/siaviewnode-server/src/logger.ts diff --git a/packages/siaviewnode-server/.gitignore b/packages/siaviewnode-server/.gitignore index 58f14456..1a404151 100644 --- a/packages/siaviewnode-server/.gitignore +++ b/packages/siaviewnode-server/.gitignore @@ -1,3 +1,5 @@ node_modules build npm-debug.log +error.log +info.log diff --git a/packages/siaviewnode-server/package-lock.json b/packages/siaviewnode-server/package-lock.json new file mode 100644 index 00000000..30c26ab4 --- /dev/null +++ b/packages/siaviewnode-server/package-lock.json @@ -0,0 +1,498 @@ +{ + "name": "siaviewnode-server", + "version": "0.0.1", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@types/body-parser": { + "version": "1.17.1", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.17.1.tgz", + "integrity": "sha512-RoX2EZjMiFMjZh9lmYrwgoP9RTpAjSHiJxdp4oidAQVO02T7HER3xj9UKue5534ULWeqVEkujhWcyvUce+d68w==", + "requires": { + "@types/connect": "*", + "@types/node": "*" + } + }, + "@types/connect": { + "version": "3.4.33", + "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.33.tgz", + "integrity": "sha512-2+FrkXY4zllzTNfJth7jOqEHC+enpLeGslEhpnTAkg21GkRrWV4SsAtqchtT4YS9/nODBU2/ZfsBY2X4J/dX7A==", + "requires": { + "@types/node": "*" + } + }, + "@types/cors": { + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.6.tgz", + "integrity": "sha512-invOmosX0DqbpA+cE2yoHGUlF/blyf7nB0OGYBBiH27crcVm5NmFaZkLP4Ta1hGaesckCi5lVLlydNJCxkTOSg==", + "requires": { + "@types/express": "*" + }, + "dependencies": { + "@types/express": { + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.2.tgz", + "integrity": "sha512-5mHFNyavtLoJmnusB8OKJ5bshSzw+qkMIBAobLrIM48HJvunFva9mOa6aBwh64lBFyNwBbs0xiEFuj4eU/NjCA==", + "requires": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "*", + "@types/serve-static": "*" + } + } + } + }, + "@types/express-fileupload": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@types/express-fileupload/-/express-fileupload-1.1.0.tgz", + "integrity": "sha512-l7ElHOlTt3Dis1My3LvEwP4tDw/cYiM1sor5nQY8aRm8HPVwalG48lf7ym9k2/z/PwRGADABGgIhv0a6y7XzoA==", + "requires": { + "@types/express": "*" + }, + "dependencies": { + "@types/express": { + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.2.tgz", + "integrity": "sha512-5mHFNyavtLoJmnusB8OKJ5bshSzw+qkMIBAobLrIM48HJvunFva9mOa6aBwh64lBFyNwBbs0xiEFuj4eU/NjCA==", + "requires": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "*", + "@types/serve-static": "*" + } + } + } + }, + "@types/express-http-proxy": { + "version": "1.5.12", + "resolved": "https://registry.npmjs.org/@types/express-http-proxy/-/express-http-proxy-1.5.12.tgz", + "integrity": "sha512-QnTNKXq3xqVU21iMtz1P1M+rhusjGqNqpcbmGzvnkrLNNCiFy6UNK/JDIYJjs3bu8AopFpnBn3wJC16K4nKSgQ==", + "requires": { + "@types/express": "*" + }, + "dependencies": { + "@types/express": { + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.2.tgz", + "integrity": "sha512-5mHFNyavtLoJmnusB8OKJ5bshSzw+qkMIBAobLrIM48HJvunFva9mOa6aBwh64lBFyNwBbs0xiEFuj4eU/NjCA==", + "requires": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "*", + "@types/serve-static": "*" + } + } + } + }, + "@types/express-request-id": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/@types/express-request-id/-/express-request-id-1.4.1.tgz", + "integrity": "sha512-39g9HGiBJBjsSJZ80vYgkR4yvu7XVL2R/R/KezU/060gnW5e9btRP7d0R8QORzJ3/Uo7Sis36AM58KSQQOfgcw==", + "requires": { + "@types/express-serve-static-core": "*" + } + }, + "@types/express-serve-static-core": { + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.2.tgz", + "integrity": "sha512-El9yMpctM6tORDAiBwZVLMcxoTMcqqRO9dVyYcn7ycLWbvR8klrDn8CAOwRfZujZtWD7yS/mshTdz43jMOejbg==", + "requires": { + "@types/node": "*", + "@types/range-parser": "*" + } + }, + "@types/mime": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@types/mime/-/mime-2.0.1.tgz", + "integrity": "sha512-FwI9gX75FgVBJ7ywgnq/P7tw+/o1GUbtP0KzbtusLigAOgIgNISRK0ZPl4qertvXSIE8YbsVJueQ90cDt9YYyw==" + }, + "@types/morgan": { + "version": "1.7.37", + "resolved": "https://registry.npmjs.org/@types/morgan/-/morgan-1.7.37.tgz", + "integrity": "sha512-tIdEA10BcHcOumMmUiiYdw8lhiVVq62r0ghih5Xpp4WETkfsMiTUZL4w9jCI502BBOrKhFrAOGml9IeELvVaBA==", + "requires": { + "@types/express": "*" + }, + "dependencies": { + "@types/express": { + "version": "4.17.2", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.2.tgz", + "integrity": "sha512-5mHFNyavtLoJmnusB8OKJ5bshSzw+qkMIBAobLrIM48HJvunFva9mOa6aBwh64lBFyNwBbs0xiEFuj4eU/NjCA==", + "requires": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "*", + "@types/serve-static": "*" + } + } + } + }, + "@types/node": { + "version": "13.1.8", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.1.8.tgz", + "integrity": "sha512-6XzyyNM9EKQW4HKuzbo/CkOIjn/evtCmsU+MUM1xDfJ+3/rNjBttM1NgN7AOQvN6tP1Sl1D1PIKMreTArnxM9A==" + }, + "@types/range-parser": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.3.tgz", + "integrity": "sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA==" + }, + "@types/serve-static": { + "version": "1.13.3", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.3.tgz", + "integrity": "sha512-oprSwp094zOglVrXdlo/4bAHtKTAxX6VT8FOZlBKrmyLbNvE1zxZyJ6yikMVtHIvwP45+ZQGJn+FdXGKTozq0g==", + "requires": { + "@types/express-serve-static-core": "*", + "@types/mime": "*" + } + }, + "@types/shortid": { + "version": "0.0.29", + "resolved": "https://registry.npmjs.org/@types/shortid/-/shortid-0.0.29.tgz", + "integrity": "sha1-gJPuBBam4r8qpjOBCRFLP7/6Dps=" + }, + "@types/winston": { + "version": "2.4.4", + "resolved": "https://registry.npmjs.org/@types/winston/-/winston-2.4.4.tgz", + "integrity": "sha512-BVGCztsypW8EYwJ+Hq+QNYiT/MUyCif0ouBH+flrY66O5W+KIXAMML6E/0fJpm7VjIzgangahl5S03bJJQGrZw==", + "requires": { + "winston": "*" + } + }, + "async": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz", + "integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==", + "requires": { + "lodash": "^4.17.14" + } + }, + "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==" + } + } + }, + "color": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/color/-/color-3.0.0.tgz", + "integrity": "sha512-jCpd5+s0s0t7p3pHQKpnJ0TpQKKdleP71LWcA0aqiljpiuAkOSUFN/dyH8ZwF0hRmFlrIuRhufds1QyEP9EB+w==", + "requires": { + "color-convert": "^1.9.1", + "color-string": "^1.5.2" + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + }, + "color-string": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/color-string/-/color-string-1.5.3.tgz", + "integrity": "sha512-dC2C5qeWoYkxki5UAXapdjqO672AM4vZuPGRQfO8b5HKuKGBbKWpITyDYN7TOFKvRW7kOgAn3746clDBMDJyQw==", + "requires": { + "color-name": "^1.0.0", + "simple-swizzle": "^0.2.2" + } + }, + "colornames": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/colornames/-/colornames-1.1.1.tgz", + "integrity": "sha1-+IiQMGhcfE/54qVZ9Qd+t2qBb5Y=" + }, + "colors": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz", + "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==" + }, + "colorspace": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/colorspace/-/colorspace-1.1.2.tgz", + "integrity": "sha512-vt+OoIP2d76xLhjwbBaucYlNSpPsrJWPlBTtwCpQKIu6/CSMutyzX93O/Do0qzpH3YoHEes8YEFXyZ797rEhzQ==", + "requires": { + "color": "3.0.x", + "text-hex": "1.0.x" + } + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" + }, + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + }, + "dependencies": { + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + } + } + }, + "depd": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", + "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" + }, + "diagnostics": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/diagnostics/-/diagnostics-1.1.1.tgz", + "integrity": "sha512-8wn1PmdunLJ9Tqbx+Fx/ZEuHfJf4NKSN2ZBj7SJC/OWRWha843+WsTjqMe1B5E3p28jqBlp+mJ2fPVxPyNgYKQ==", + "requires": { + "colorspace": "1.1.x", + "enabled": "1.0.x", + "kuler": "1.0.x" + } + }, + "ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" + }, + "enabled": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/enabled/-/enabled-1.0.2.tgz", + "integrity": "sha1-ll9lE9LC0cX0ZStkouM5ZGf8L5M=", + "requires": { + "env-variable": "0.0.x" + } + }, + "env-variable": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/env-variable/-/env-variable-0.0.5.tgz", + "integrity": "sha512-zoB603vQReOFvTg5xMl9I1P2PnHsHQQKTEowsKKD7nseUfJq6UWzK+4YtlWUO1nhiQUxe6XMkk+JleSZD1NZFA==" + }, + "express-request-id": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/express-request-id/-/express-request-id-1.4.1.tgz", + "integrity": "sha512-qpxK6XhDYtdx9FvxwCHkUeZVWtkGbWR87hBAzGECfwYF/QQCPXEwwB2/9NGkOR1tT7/aLs9mma3CT0vjSzuZVw==", + "requires": { + "uuid": "^3.3.2" + } + }, + "fast-safe-stringify": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.0.7.tgz", + "integrity": "sha512-Utm6CdzT+6xsDk2m8S6uL8VHxNwI6Jub+e9NYTcAms28T84pTa25GJQV9j0CY0N1rM8hK4x6grpF2BQf+2qwVA==" + }, + "fecha": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fecha/-/fecha-2.3.3.tgz", + "integrity": "sha512-lUGBnIamTAwk4znq5BcqsDaxSmZ9nDVJaij6NvRt/Tg4R69gERA+otPKbS86ROw9nxVMw2/mp1fnaiWqbs6Sdg==" + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "is-arrayish": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz", + "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==" + }, + "is-stream": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", + "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" + }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" + }, + "kuler": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/kuler/-/kuler-1.0.1.tgz", + "integrity": "sha512-J9nVUucG1p/skKul6DU3PUZrhs0LPulNaeUOox0IyXDi8S4CztTHs1gQphhuZmzXG7VOQSf6NJfKuzteQLv9gQ==", + "requires": { + "colornames": "^1.1.1" + } + }, + "lodash": { + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" + }, + "logform": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/logform/-/logform-2.1.2.tgz", + "integrity": "sha512-+lZh4OpERDBLqjiwDLpAWNQu6KMjnlXH2ByZwCuSqVPJletw0kTWJf5CgSNAUKn1KUkv3m2cUz/LK8zyEy7wzQ==", + "requires": { + "colors": "^1.2.1", + "fast-safe-stringify": "^2.0.4", + "fecha": "^2.3.3", + "ms": "^2.1.1", + "triple-beam": "^1.3.0" + } + }, + "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" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, + "on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", + "requires": { + "ee-first": "1.1.1" + } + }, + "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==" + }, + "one-time": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/one-time/-/one-time-0.0.4.tgz", + "integrity": "sha1-+M33eISCb+Tf+T46nMN7HkSAdC4=" + }, + "process-nextick-args": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" + }, + "readable-stream": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.5.0.tgz", + "integrity": "sha512-gSz026xs2LfxBPudDuI41V1lka8cxg64E66SGe78zJlsUofOg/yqwezdIcdfwik6B4h8LFmWPA9ef9X3FiNFLA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + }, + "safe-buffer": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz", + "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==" + }, + "simple-swizzle": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz", + "integrity": "sha1-pNprY1/8zMoz9w0Xy5JZLeleVXo=", + "requires": { + "is-arrayish": "^0.3.1" + } + }, + "stack-trace": { + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz", + "integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA=" + }, + "string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "requires": { + "safe-buffer": "~5.2.0" + } + }, + "text-hex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/text-hex/-/text-hex-1.0.0.tgz", + "integrity": "sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg==" + }, + "triple-beam": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.3.0.tgz", + "integrity": "sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==" + }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + }, + "uuid": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", + "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==" + }, + "winston": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/winston/-/winston-3.2.1.tgz", + "integrity": "sha512-zU6vgnS9dAWCEKg/QYigd6cgMVVNwyTzKs81XZtTFuRwJOcDdBg7AU0mXVyNbs7O5RH2zdv+BdNZUlx7mXPuOw==", + "requires": { + "async": "^2.6.1", + "diagnostics": "^1.1.1", + "is-stream": "^1.1.0", + "logform": "^2.1.1", + "one-time": "0.0.4", + "readable-stream": "^3.1.1", + "stack-trace": "0.0.x", + "triple-beam": "^1.3.0", + "winston-transport": "^4.3.0" + } + }, + "winston-transport": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/winston-transport/-/winston-transport-4.3.0.tgz", + "integrity": "sha512-B2wPuwUi3vhzn/51Uukcao4dIduEiPOcOt9HJ3QeaXgkJ5Z7UwpBzxS4ZGNHtrxrUvTwemsQiSys0ihOf8Mp1A==", + "requires": { + "readable-stream": "^2.3.6", + "triple-beam": "^1.2.0" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "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==" + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "requires": { + "safe-buffer": "~5.1.0" + } + } + } + } + } +} diff --git a/packages/siaviewnode-server/package.json b/packages/siaviewnode-server/package.json index 14d3c55b..e9a4738b 100644 --- a/packages/siaviewnode-server/package.json +++ b/packages/siaviewnode-server/package.json @@ -8,7 +8,14 @@ }, "license": "MIT", "dependencies": { + "@types/cors": "^2.8.6", "@types/express": "^4.0.34", + "@types/express-fileupload": "^1.1.0", + "@types/express-http-proxy": "^1.5.12", + "@types/express-request-id": "^1.4.1", + "@types/morgan": "^1.7.37", + "@types/shortid": "0.0.29", + "@types/winston": "^2.4.4", "awesome-typescript-loader": "^5.2.1", "axios": "0.19.0", "backpack-core": "^0.8.4", @@ -16,10 +23,13 @@ "express": "^4.14.0", "express-fileupload": "1.1.6", "express-http-proxy": "1.6.0", + "express-request-id": "^1.4.1", "express-session": "1.17.0", + "morgan": "^1.9.1", "ramda": "0.26.1", "shortid": "2.2.15", - "typescript": "^3.5.2" + "typescript": "^3.5.2", + "winston": "^3.2.1" }, "devDependencies": { "@types/ramda": "0.26.36" diff --git a/packages/siaviewnode-server/src/access.log b/packages/siaviewnode-server/src/access.log new file mode 100644 index 00000000..e69de29b diff --git a/packages/siaviewnode-server/src/logger.ts b/packages/siaviewnode-server/src/logger.ts new file mode 100644 index 00000000..edb79a91 --- /dev/null +++ b/packages/siaviewnode-server/src/logger.ts @@ -0,0 +1,18 @@ +import { createLogger, format, transports } from 'winston'; + +const { combine, timestamp, prettyPrint } = format; + +const logger = createLogger({ + format: combine( + timestamp(), + prettyPrint(), + ), + transports: [ + new transports.Console(), + new transports.File({ filename: './error.log', level: 'error' }), + new transports.File({ filename: './info.log', level: 'info' }), + ], + exitOnError: false, +}); + +export default logger; \ No newline at end of file diff --git a/packages/siaviewnode-server/src/main.ts b/packages/siaviewnode-server/src/main.ts index b2dd7b9a..0d70605d 100644 --- a/packages/siaviewnode-server/src/main.ts +++ b/packages/siaviewnode-server/src/main.ts @@ -1,11 +1,16 @@ import axios from "axios" -import * as cors from "cors" -import * as express from "express" -import * as fileUpload from "express-fileupload" -import * as proxy from "express-http-proxy" -import * as R from "ramda" -import * as shortid from "shortid" +import cors from "cors" +import express, { Request, Response } from "express" +import fileUpload, { UploadedFile } from "express-fileupload" +import proxy from "express-http-proxy" +import requestId from "express-request-id" +import morgan from 'morgan' +import R from "ramda" +import shortid from "shortid" +import { Logger } from "winston" +import logger from "./logger" +const MAX_UPLOAD_FILESIZE = 1000 * 1024 * 1024 const SIAD_ENDPOINT = "http://localhost:9980" // simple siad connection with static strings @@ -25,119 +30,101 @@ const siad = axios.create({ const selectFile = R.path(["files", "file"]) const pName = R.prop("name") -declare var __DEV__: boolean - export class Server { public app: express.Express - public port: number - constructor() { + constructor(private logger: Logger) { this.boot() } + + private boot() { this.app = express() - this.port = this.getPort() - this.setRoutes() - this.start() + + this.logger.info("Configuring middleware...") + this.configureMiddleware() + + this.logger.info("Configuring routes...") + this.configureRoutes() + + this.logger.info("Booting server...") + const port = parseInt(process.env.PORT, 10) || 3000 + this.app.listen(port, () => { + this.logger.info(`Listening on port ${port}`) + }) } - private start = (): void => { - this.app.listen(this.port, this.onListen) - } - - private onListen = (err: any): void => { - if (err) { - console.error(err) - return + private configureMiddleware() { + // add morgan middleware (HTTP request logging) + const options = { + stream: { + write: (msg: string) => { this.logger.info(msg) } + } } + this.app.use(morgan("combined", options)); - if (__DEV__) { - console.log("> in development") - } + // add request id middleware (add unique id to X-Request-Id header) + this.app.use(requestId()) - console.log(`> listening on port ${this.port}`) + // configure CORS (simply enable all CORS requests) + this.app.use(cors()) + + // configure upload limits + this.app.use(fileUpload({ limits: { fileSize: MAX_UPLOAD_FILESIZE } })) } - private getPort = (): number => parseInt(process.env.PORT, 10) || 3000 - - private setRoutes = (): void => { - this.app.use( - cors({ - origin: "*", - credentials: true - }) - ) - this.app.use( - fileUpload({ - limits: { fileSize: 1000 * 1024 * 1024 } - }) - ) - // siafile - this.app.post("/siafile", this.postSiaFile) - // linkfile - this.app.get( - "/sialink/:hash", - proxy("http://localhost:9980/renter/sialink", { - proxyReqOptDecorator: (opts, _) => { - opts.headers["User-Agent"] = "Sia-Agent" - return opts - }, - proxyReqPathResolver: req => { - const { hash } = req.params - return `/renter/sialink/${hash}` - } - }) - ) - this.app.post("/linkfile", this.handleLinkUpload) + private configureRoutes() { + this.app.get("/sialink/:hash", this.handleSialinkGET.bind(this)) + this.app.post("/siafile", this.handleSiafilePOST.bind(this)) + this.app.post("/linkfile", this.handleLinkfilePOST.bind(this)) } - private async handleLinkUpload( - req: express.Request, - res: express.Response - ): Promise { - const fileToUpload: any = selectFile(req) - console.log("file:", fileToUpload) - const filename = pName(fileToUpload) - console.log("filename:", filename) + private handleSialinkGET() { + return proxy(`${SIAD_ENDPOINT}/renter/sialink`, { + proxyReqOptDecorator: (opts, _) => { + opts.headers["User-Agent"] = "Sia-Agent" + return opts + }, + proxyReqPathResolver: req => { + const { hash } = req.params + return `/renter/sialink/${hash}` + } + }) + } + + private async handleLinkfilePOST(req: Request, res: Response): Promise { + const file = selectFile(req) as UploadedFile const uid = shortid.generate() - console.log("uid:", uid) + + this.logger.info(`POST linkfile w/name ${file.name} and uid ${uid}`) + try { const { data } = await siad.post( `/renter/linkfile/linkfiles/${uid}`, - fileToUpload.data, + file.data, { - maxContentLength: 1000 * 1024 * 1024, - params: { - name: filename - } + maxContentLength: MAX_UPLOAD_FILESIZE, + params: { name: file.name } } ) - console.log("data is ", data) return res.send(data) } catch (err) { - console.log("err", err.message) - return res.sendStatus(500) + const { message } = err; + this.logger.error(message) + return res.status(500).send({ error: err.message }) } } - private async postSiaFile( - req: express.Request & any, - res: express.Response - ): Promise { + private async handleSiafilePOST(req: Request, res: Response): Promise { + const file = selectFile(req) as UploadedFile + const selectContentLength = R.path(["headers", "Content-Length"]) + const cl = selectContentLength(req) + + this.logger.info(`POST siafile ${file.name} w/contentlength ${cl}`) + try { - const file: any = selectFile(req) - - const selectContentLength = R.path(["headers", "Content-Length"]) - const cl = selectContentLength(req) - console.log("cl is", cl) - - console.log("file is", file) - const { data: stream, headers } = await siad.post( "/renter/stream", file.data, - { - responseType: "stream" - } + { responseType: "stream" } ) - const contentLength = headers["Content-Length"] const splitFilename = R.compose(R.head, R.split(".sia")) const fileName = R.compose(splitFilename, pName)(file) @@ -146,13 +133,14 @@ export class Server { "Content-Disposition", `attachment; filename="${fileName}"; filename*="${fileName}"` ) - res.set("Content-Length", contentLength) - stream.pipe(res) - } catch (e) { - console.log("postSiaFile err:", e) - return res.json({ error: e.message }) + res.set("Content-Length", headers["Content-Length"]) + return stream.pipe(res) + } catch (err) { + const { message } = err; + this.logger.error(message) + return res.status(500).send({ error: err.message }) } } } -module.exports = new Server().app +module.exports = new Server(logger).app diff --git a/packages/siaviewnode-server/tsconfig.json b/packages/siaviewnode-server/tsconfig.json index 85b5edd0..f21c6d79 100644 --- a/packages/siaviewnode-server/tsconfig.json +++ b/packages/siaviewnode-server/tsconfig.json @@ -1,7 +1,25 @@ { "compilerOptions": { - "lib": ["es5", "es2015.promise", "dom"], + "module": "commonjs", + "noImplicitReturns": true, + "noUnusedLocals": true, + "sourceMap": true, "strict": false, - "skipLibCheck": true + "lib": [ + "es2017", + "dom" + ], + "target": "es2017", + "esModuleInterop": true + }, + "compileOnSave": true, + "exclude": [ + "node_modules", + "../../node_modules" + ], + "awesomeTypescriptLoaderOptions": { + "reportFiles": [ + "./src/**/*" + ] } -} +} \ No newline at end of file