core: bug fix

This commit is contained in:
undefined committed 2022-09-21 16:31:12 +08:00
1 parent 0ed92b6af5
commit 18cd033664
3 files changed
+7 -3

No files matched your search

-1
View File
@@ -28,5 +28,4 @@ if (!global.Hydro) {
locales: {},
};
global.addons = [];
global.publicDirs = [];
}
+1
View File
@@ -716,6 +716,7 @@ export interface UI {
export interface HydroGlobal {
version: Record<string, string>,
model: Model,
/** @deprecated */
handler: Record<string, Function>,
script: Record<string, Script>,
service: Service,
+6 -2
View File
@@ -1,5 +1,7 @@
import http from 'http';
import path from 'path';
import cac from 'cac';
import fs from 'fs-extra';
import Koa, { Context } from 'koa';
import Body from 'koa-body';
import Compress from 'koa-compress';
@@ -117,7 +119,9 @@ export async function prepare() {
return await next();
});
app.use(Compress());
for (const dir of global.publicDirs) {
for (const addon of global.addons) {
const dir = path.resolve(addon, 'public');
if (!fs.existsSync(dir)) continue;
app.use(cache(dir, {
maxAge: argv.options.public ? 0 : 24 * 3600 * 1000,
}));
@@ -143,7 +147,7 @@ ${ctx.response.status} ${endTime - startTime}ms ${ctx.response.length}`);
}));
const layers = [baseLayer, rendererLayer(router, logger), responseLayer(logger), userLayer];
app.use(async (ctx, next) => await next().catch(console.error)).use(domainLayer);
layers.forEach((layer) => router.use(layer as any));
layers.forEach((layer) => app.use(layer as any));
wsServer.on('connection', async (socket, request) => {
const ctx: any = app.createContext(request, {} as any);
await domainLayer(ctx, () => baseLayer(ctx, () => layers[1](ctx, () => userLayer(ctx, () => { }))));