init
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user