mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: 压缩响应内容
This commit is contained in:
1 parent
33bc45c5ab
commit
1ec793d039
2 files changed
+15
-12
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.20.36",
|
||||
"version": "2.20.37",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
@@ -20,6 +20,7 @@
|
||||
"js-yaml": "^4.0.0",
|
||||
"koa": "^2.13.1",
|
||||
"koa-body": "^4.2.0",
|
||||
"koa-compress": "^5.0.1",
|
||||
"koa-proxies": "^0.11.0",
|
||||
"koa-router": "^10.0.0",
|
||||
"koa-static-cache": "^5.1.3",
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
import { ObjectID } from 'mongodb';
|
||||
import Koa, { Context } from 'koa';
|
||||
import Body from 'koa-body';
|
||||
import Compress from 'koa-compress';
|
||||
import Router from 'koa-router';
|
||||
import proxy from 'koa-proxies';
|
||||
import cache from 'koa-static-cache';
|
||||
@@ -230,15 +231,26 @@ export async function prepare() {
|
||||
changeOrigin: true,
|
||||
rewrite: (p) => p.replace('/fs', ''),
|
||||
}));
|
||||
app.use(Compress());
|
||||
if (argv.public) {
|
||||
app.use(cache(argv.public, {
|
||||
maxAge: 0,
|
||||
}));
|
||||
} else {
|
||||
app.use(cache(resolve(os.tmpdir(), 'hydro', 'public'), {
|
||||
maxAge: 365 * 24 * 60 * 60,
|
||||
maxAge: 30 * 24 * 60 * 60,
|
||||
}));
|
||||
}
|
||||
if (argv.debug) {
|
||||
app.use(async (ctx: Context, next: Function) => {
|
||||
const startTime = new Date().getTime();
|
||||
await next();
|
||||
const endTime = new Date().getTime();
|
||||
if (ctx.nolog || ctx.response.headers.nolog) return;
|
||||
ctx._remoteAddress = ctx.request.ip;
|
||||
logger.debug(`${ctx.request.method} ${ctx.request.path} ${ctx.response.status} ${endTime - startTime}ms ${ctx.response.length}`);
|
||||
});
|
||||
}
|
||||
app.use(Body({
|
||||
multipart: true,
|
||||
formidable: {
|
||||
@@ -786,16 +798,6 @@ export function Connection(
|
||||
// TODO use postInit?
|
||||
export function start() {
|
||||
const port = system.get('server.port');
|
||||
if (argv.debug) {
|
||||
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;
|
||||
logger.debug(`${ctx.request.method} ${ctx.request.path} ${ctx.response.status} ${endTime - startTime}ms ${ctx.response.length}`);
|
||||
});
|
||||
}
|
||||
app.use(router.routes()).use(router.allowedMethods());
|
||||
server.listen(argv.port || port);
|
||||
logger.success('Server listening at: %d', argv.port || port);
|
||||
|
||||
Reference in new issue
Block a user