feat: add server logger

This commit is contained in:
moonrailgun 2023-09-05 14:08:38 +08:00
parent af96679e0b
commit 6441230df4
5 changed files with 48 additions and 0 deletions

View File

@ -34,6 +34,7 @@
"jsonwebtoken": "^9.0.2", "jsonwebtoken": "^9.0.2",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"maxmind": "^4.3.11", "maxmind": "^4.3.11",
"morgan": "^1.10.0",
"nanoid": "^3.3.6", "nanoid": "^3.3.6",
"passport": "^0.6.0", "passport": "^0.6.0",
"passport-jwt": "^4.0.1", "passport-jwt": "^4.0.1",
@ -57,6 +58,7 @@
"@types/express": "^4.17.17", "@types/express": "^4.17.17",
"@types/jsonwebtoken": "^9.0.2", "@types/jsonwebtoken": "^9.0.2",
"@types/lodash-es": "^4.17.9", "@types/lodash-es": "^4.17.9",
"@types/morgan": "^1.9.5",
"@types/node": "^18.17.12", "@types/node": "^18.17.12",
"@types/passport": "^1.0.12", "@types/passport": "^1.0.12",
"@types/passport-jwt": "^3.0.9", "@types/passport-jwt": "^3.0.9",

View File

@ -64,6 +64,9 @@ dependencies:
maxmind: maxmind:
specifier: ^4.3.11 specifier: ^4.3.11
version: 4.3.11 version: 4.3.11
morgan:
specifier: ^1.10.0
version: 1.10.0
nanoid: nanoid:
specifier: ^3.3.6 specifier: ^3.3.6
version: 3.3.6 version: 3.3.6
@ -129,6 +132,9 @@ devDependencies:
'@types/lodash-es': '@types/lodash-es':
specifier: ^4.17.9 specifier: ^4.17.9
version: 4.17.9 version: 4.17.9
'@types/morgan':
specifier: ^1.9.5
version: 1.9.5
'@types/node': '@types/node':
specifier: ^18.17.12 specifier: ^18.17.12
version: 18.17.12 version: 18.17.12
@ -1962,6 +1968,12 @@ packages:
resolution: {integrity: sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==} resolution: {integrity: sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==}
dev: true dev: true
/@types/morgan@1.9.5:
resolution: {integrity: sha512-5TgfIWm0lcTGnbCZExwc19dCOMOMmAiiBZQj8Ko3NRxsVDgRxf+AEGRQTqNVA5Yh2xfdWp4clbAEMbYP+jkOqg==}
dependencies:
'@types/node': 18.17.12
dev: true
/@types/node@18.17.12: /@types/node@18.17.12:
resolution: {integrity: sha512-d6xjC9fJ/nSnfDeU0AMDsaJyb1iHsqCSOdi84w4u+SlN/UgQdY5tRhpMzaFYsI4mnpvgTivEaQd0yOUhAtOnEQ==} resolution: {integrity: sha512-d6xjC9fJ/nSnfDeU0AMDsaJyb1iHsqCSOdi84w4u+SlN/UgQdY5tRhpMzaFYsI4mnpvgTivEaQd0yOUhAtOnEQ==}
@ -2312,6 +2324,13 @@ packages:
engines: {node: ^4.5.0 || >= 5.9} engines: {node: ^4.5.0 || >= 5.9}
dev: false dev: false
/basic-auth@2.0.1:
resolution: {integrity: sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==}
engines: {node: '>= 0.8'}
dependencies:
safe-buffer: 5.1.2
dev: false
/bcryptjs@2.4.3: /bcryptjs@2.4.3:
resolution: {integrity: sha512-V/Hy/X9Vt7f3BbPJEi8BdVFMByHi+jNXrYkW3huaybV/kQ0KJg0Y6PkEMbn+zeT+i+SiKZ/HMqJGIIt4LZDqNQ==} resolution: {integrity: sha512-V/Hy/X9Vt7f3BbPJEi8BdVFMByHi+jNXrYkW3huaybV/kQ0KJg0Y6PkEMbn+zeT+i+SiKZ/HMqJGIIt4LZDqNQ==}
dev: false dev: false
@ -4009,6 +4028,19 @@ packages:
resolution: {integrity: sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==} resolution: {integrity: sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==}
dev: false dev: false
/morgan@1.10.0:
resolution: {integrity: sha512-AbegBVI4sh6El+1gNwvD5YIck7nSA36weD7xvIxG4in80j/UoK8AEGaWnnz8v1GxonMCltmlNs5ZKbGvl9b1XQ==}
engines: {node: '>= 0.8.0'}
dependencies:
basic-auth: 2.0.1
debug: 2.6.9
depd: 2.0.0
on-finished: 2.3.0
on-headers: 1.0.2
transitivePeerDependencies:
- supports-color
dev: false
/mousetrap@1.6.5: /mousetrap@1.6.5:
resolution: {integrity: sha512-QNo4kEepaIBwiT8CDhP98umTetp+JNfQYBWvC1pc6/OAibuXtRcxZ58Qz8skvEHYvURne/7R8T5VoOI7rDsEUA==} resolution: {integrity: sha512-QNo4kEepaIBwiT8CDhP98umTetp+JNfQYBWvC1pc6/OAibuXtRcxZ58Qz8skvEHYvURne/7R8T5VoOI7rDsEUA==}
dev: false dev: false
@ -4137,6 +4169,13 @@ packages:
object-keys: 1.1.1 object-keys: 1.1.1
dev: false dev: false
/on-finished@2.3.0:
resolution: {integrity: sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww==}
engines: {node: '>= 0.8'}
dependencies:
ee-first: 1.1.1
dev: false
/on-finished@2.4.1: /on-finished@2.4.1:
resolution: {integrity: sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==} resolution: {integrity: sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==}
engines: {node: '>= 0.8'} engines: {node: '>= 0.8'}

View File

@ -1,5 +1,7 @@
import * as user from './user'; import * as user from './user';
import * as website from './website';
export const model = { export const model = {
user, user,
website,
}; };

View File

@ -4,6 +4,7 @@ import 'express-async-errors';
import ViteExpress from 'vite-express'; import ViteExpress from 'vite-express';
import compression from 'compression'; import compression from 'compression';
import passport from 'passport'; import passport from 'passport';
import morgan from 'morgan';
import { userRouter } from './router/user'; import { userRouter } from './router/user';
import { websiteRouter } from './router/website'; import { websiteRouter } from './router/website';
import { workspaceRouter } from './router/workspace'; import { workspaceRouter } from './router/workspace';
@ -15,6 +16,7 @@ const app = express();
app.use(compression()); app.use(compression());
app.use(express.json()); app.use(express.json());
app.use(passport.initialize()); app.use(passport.initialize());
app.use(morgan('tiny'));
// http://expressjs.com/en/advanced/best-practice-security.html#at-a-minimum-disable-x-powered-by-header // http://expressjs.com/en/advanced/best-practice-security.html#at-a-minimum-disable-x-powered-by-header
app.disable('x-powered-by'); app.disable('x-powered-by');

3
src/server/tsconfig.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "../../tsconfig.json",
}