This commit is contained in:
xy
2026-03-13 01:38:40 +00:00
parent e6e4f88257
commit 28855885cd
311 changed files with 89544 additions and 94350 deletions
+10 -2
View File
@@ -2,6 +2,14 @@ import c2k = require('koa-connect');
import { createProxyMiddleware, Options as ContextOptions } from 'http-proxy-middleware';
import * as micromatch from 'micromatch';
import * as isGlob from 'is-glob';
import { Context } from 'egg';
// 扩展Request接口,添加rawBody属性
declare module 'egg' {
interface Request {
rawBody: string;
}
}
function match(context: string, path: string): boolean {
// single path
@@ -19,7 +27,7 @@ export interface Options {
}
export default function (options: Options) {
return async (ctx, next) => {
return async (ctx: Context, next: () => Promise<any>) => {
for (const context of Object.keys(options)) {
if (match(context, ctx.path)) {
const contextOptions: ContextOptions = options[context];
@@ -41,7 +49,7 @@ export default function (options: Options) {
return proxyReq;
},
}) as any
)(ctx, next);
)(ctx as any, next);
}
}
await next();