feat: add cors and morgan logger

This commit is contained in:
moonrailgun 2023-10-28 20:12:53 +08:00
parent 1631521321
commit b376db7f92
3 changed files with 14 additions and 5 deletions

View File

@ -38,6 +38,7 @@
"colord": "^2.9.3", "colord": "^2.9.3",
"compose-middleware": "^5.0.1", "compose-middleware": "^5.0.1",
"compression": "^1.7.4", "compression": "^1.7.4",
"cors": "^2.8.5",
"croner": "^7.0.1", "croner": "^7.0.1",
"dayjs": "^1.11.9", "dayjs": "^1.11.9",
"detect-browser": "^5.3.0", "detect-browser": "^5.3.0",
@ -83,6 +84,7 @@
"devDependencies": { "devDependencies": {
"@types/bcryptjs": "^2.4.3", "@types/bcryptjs": "^2.4.3",
"@types/compression": "^1.7.2", "@types/compression": "^1.7.2",
"@types/cors": "^2.8.15",
"@types/express": "^4.17.17", "@types/express": "^4.17.17",
"@types/jsonwebtoken": "^9.0.2", "@types/jsonwebtoken": "^9.0.2",
"@types/lodash": "^4.14.198", "@types/lodash": "^4.14.198",

13
pnpm-lock.yaml generated
View File

@ -55,6 +55,9 @@ dependencies:
compression: compression:
specifier: ^1.7.4 specifier: ^1.7.4
version: 1.7.4 version: 1.7.4
cors:
specifier: ^2.8.5
version: 2.8.5
croner: croner:
specifier: ^7.0.1 specifier: ^7.0.1
version: 7.0.1 version: 7.0.1
@ -186,6 +189,9 @@ devDependencies:
'@types/compression': '@types/compression':
specifier: ^1.7.2 specifier: ^1.7.2
version: 1.7.2 version: 1.7.2
'@types/cors':
specifier: ^2.8.15
version: 2.8.15
'@types/express': '@types/express':
specifier: ^4.17.17 specifier: ^4.17.17
version: 4.17.17 version: 4.17.17
@ -2040,11 +2046,10 @@ packages:
resolution: {integrity: sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q==} resolution: {integrity: sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q==}
dev: false dev: false
/@types/cors@2.8.13: /@types/cors@2.8.15:
resolution: {integrity: sha512-RG8AStHlUiV5ysZQKq97copd2UmVYw3/pRMLefISZ3S1hK104Cwm7iLQ3fTKx+lsUH2CE8FlLaYeEA2LSeqYUA==} resolution: {integrity: sha512-n91JxbNLD8eQIuXDIChAN1tCKNWCEgpceU9b7ZMbFA+P+Q4yIeh80jizFLEvolRPc1ES0VdwFlGv+kJTSirogw==}
dependencies: dependencies:
'@types/node': 18.17.12 '@types/node': 18.17.12
dev: false
/@types/d3-timer@2.0.1: /@types/d3-timer@2.0.1:
resolution: {integrity: sha512-TF8aoF5cHcLO7W7403blM7L1T+6NF3XMyN3fxyUolq2uOcFeicG/khQg/dGxiCJWoAcmYulYN7LYSRKO54IXaA==} resolution: {integrity: sha512-TF8aoF5cHcLO7W7403blM7L1T+6NF3XMyN3fxyUolq2uOcFeicG/khQg/dGxiCJWoAcmYulYN7LYSRKO54IXaA==}
@ -3361,7 +3366,7 @@ packages:
engines: {node: '>=10.2.0'} engines: {node: '>=10.2.0'}
dependencies: dependencies:
'@types/cookie': 0.4.1 '@types/cookie': 0.4.1
'@types/cors': 2.8.13 '@types/cors': 2.8.15
'@types/node': 18.17.12 '@types/node': 18.17.12
accepts: 1.3.8 accepts: 1.3.8
base64id: 2.0.0 base64id: 2.0.0

View File

@ -21,6 +21,7 @@ import { initSocketio } from './ws';
import { monitorManager } from './model/monitor'; import { monitorManager } from './model/monitor';
import { settings } from './utils/settings'; import { settings } from './utils/settings';
import { env } from './utils/env'; import { env } from './utils/env';
import cors from 'cors';
const port = settings.port; const port = settings.port;
@ -36,7 +37,8 @@ monitorManager.startAll();
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')); app.use(morgan('tiny'));
app.use(cors());
// 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');