mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: fix load
This commit is contained in:
1 parent
aeb9d4cf50
commit
dec3170524
3 files changed
+20
-6
No files matched your search
@@ -42,6 +42,11 @@ export async function apply(ctx: Context) {
|
|||||||
ctx.plugin(require('../service/hmr').default, { watch: argv.options.watch });
|
ctx.plugin(require('../service/hmr').default, { watch: argv.options.watch });
|
||||||
await require('../service/worker').apply(ctx);
|
await require('../service/worker').apply(ctx);
|
||||||
await require('../service/server').apply(ctx);
|
await require('../service/server').apply(ctx);
|
||||||
|
ctx = await new Promise((resolve) => {
|
||||||
|
ctx.inject(['server'], (c) => {
|
||||||
|
resolve(c);
|
||||||
|
});
|
||||||
|
});
|
||||||
await require('../service/api').apply(ctx);
|
await require('../service/api').apply(ctx);
|
||||||
require('../lib/index');
|
require('../lib/index');
|
||||||
await lib(pending, fail, ctx);
|
await lib(pending, fail, ctx);
|
||||||
|
|||||||
@@ -138,9 +138,16 @@ export class Loader extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.plugin(I18n);
|
app.plugin(I18n);
|
||||||
app.plugin(Loader);
|
|
||||||
|
|
||||||
function preload() {
|
async function preload() {
|
||||||
|
global.app = await new Promise((resolve) => {
|
||||||
|
app.inject(['timer', 'i18n', 'logger'], (c) => {
|
||||||
|
c.plugin(Loader);
|
||||||
|
c.inject(['loader'], (ctx) => {
|
||||||
|
resolve(ctx);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
for (const a of [path.resolve(__dirname, '..'), ...getAddons()]) {
|
for (const a of [path.resolve(__dirname, '..'), ...getAddons()]) {
|
||||||
try {
|
try {
|
||||||
// Is a npm package
|
// Is a npm package
|
||||||
@@ -160,7 +167,7 @@ function preload() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function load() {
|
export async function load() {
|
||||||
preload();
|
await preload();
|
||||||
Error.stackTraceLimit = 50;
|
Error.stackTraceLimit = 50;
|
||||||
try {
|
try {
|
||||||
const { simpleGit } = require('simple-git') as typeof import('simple-git');
|
const { simpleGit } = require('simple-git') as typeof import('simple-git');
|
||||||
@@ -199,7 +206,7 @@ export async function load() {
|
|||||||
|
|
||||||
export async function loadCli() {
|
export async function loadCli() {
|
||||||
process.env.HYDRO_CLI = 'true';
|
process.env.HYDRO_CLI = 'true';
|
||||||
preload();
|
await preload();
|
||||||
await require('./entry/cli').load(app);
|
await require('./entry/cli').load(app);
|
||||||
setTimeout(() => process.exit(0), 300);
|
setTimeout(() => process.exit(0), 300);
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,9 @@ import proxy from 'koa-proxies';
|
|||||||
import cache from 'koa-static-cache';
|
import cache from 'koa-static-cache';
|
||||||
import { type FindCursor, ObjectId } from 'mongodb';
|
import { type FindCursor, ObjectId } from 'mongodb';
|
||||||
import {
|
import {
|
||||||
ConnectionHandler as ConnectionHandlerOriginal, Handler as HandlerOriginal, HydroError, NotFoundError, UserFacingError,
|
ConnectionHandler as ConnectionHandlerOriginal,
|
||||||
|
Handler as HandlerOriginal, HydroError, NotFoundError, UserFacingError,
|
||||||
|
WebService,
|
||||||
} from '@hydrooj/framework';
|
} from '@hydrooj/framework';
|
||||||
import { errorMessage, Time } from '@hydrooj/utils';
|
import { errorMessage, Time } from '@hydrooj/utils';
|
||||||
import { Context } from '../context';
|
import { Context } from '../context';
|
||||||
@@ -130,7 +132,7 @@ export class ConnectionHandler extends ConnectionHandlerOriginal<Context> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function apply(ctx: Context) {
|
export async function apply(ctx: Context) {
|
||||||
ctx.plugin(require('@hydrooj/framework'), {
|
ctx.plugin(WebService, {
|
||||||
keys: system.get('session.keys'),
|
keys: system.get('session.keys'),
|
||||||
proxy: !!system.get('server.xproxy') || !!system.get('server.xff'),
|
proxy: !!system.get('server.xproxy') || !!system.get('server.xff'),
|
||||||
cors: system.get('server.cors') || '',
|
cors: system.get('server.cors') || '',
|
||||||
|
|||||||
Reference in new issue
Block a user