移除koa-morgan

This commit is contained in:
undefined committed 2020-09-09 23:17:55 +08:00
1 parent d458c231a4
commit 9e225f5daa
2 files changed
+17 -8

No files matched your search

+1 -3
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.13.8",
"version": "2.13.9",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
@@ -19,7 +19,6 @@
"js-yaml": "^3.13.1",
"koa": "^2.13.0",
"koa-body": "^4.2.0",
"koa-morgan": "^1.0.1",
"koa-router": "^9.4.0",
"koa-static-cache": "^5.1.3",
"lodash": "^4.17.20",
@@ -40,7 +39,6 @@
"@types/fs-extra": "^9.0.1",
"@types/js-yaml": "^3.12.5",
"@types/koa": "^2.11.4",
"@types/koa-morgan": "^1.0.4",
"@types/koa-router": "^7.4.1",
"@types/koa-static-cache": "^5.1.0",
"@types/lodash": "^4.14.161",
+16 -5
View File
@@ -7,8 +7,7 @@ import http from 'http';
import moment from 'moment-timezone';
import { isSafeInteger, Dictionary, filter } from 'lodash';
import { ObjectID } from 'mongodb';
import Koa from 'koa';
import morgan from 'koa-morgan';
import Koa, { Context } from 'koa';
import Body from 'koa-body';
import Router from 'koa-router';
import cache from 'koa-static-cache';
@@ -806,9 +805,21 @@ export function Connection(
export async function start() {
const port = await system.get('server.port');
if (argv.debug) {
app.use(morgan(':method :url :status :res[content-length] - :response-time ms', {
skip: (req, res) => res.hasHeader('nolog'),
}));
app.use(async (ctx: Context, next: Function) => {
const startTime = new Date().getTime();
await next();
const endTime = new Date().getTime();
if (ctx.response.headers.nolog) return;
ctx._remoteAddress = ctx.request.ip;
const status = ctx.response.status;
const color = status >= 500 ? 31 // red
: status >= 400 ? 33 // yellow
: status >= 300 ? 36 // cyan
: status >= 200 ? 32 // green
: 0; // no color
logger.debug(`\
\x1b[0m${ctx.request.method} ${ctx.request.path} \x1b[${color}m${ctx.response.status}\x1b[0m ${endTime - startTime}ms ${ctx.response.length}\x1b[0m`);
});
}
app.use(async (ctx, next) => {
const xff = await system.get('server.xff');