"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const proxy = require("http-proxy-middleware");
const k2c = require("koa2-connect");
const pathToRegexp = require("path-to-regexp");
const config_1 = require("../config");
const { PROXY } = config_1.default;
// 代理请求中间件
// 配置文件在 app/config/config.default.ts 或对应的 config.{env}.ts
function default_1(ctx, next) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const { path } = ctx;
        const routes = Object.keys(PROXY);
        for (const route of routes) {
            if (path.startsWith(route) || pathToRegexp(route).test(path)) {
                yield k2c(proxy(PROXY[route]))(ctx, next);
                break;
            }
        }
        yield next();
    });
}
exports.default = default_1;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJveHkuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbWlkZGxld2FyZS9wcm94eS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFDQSwrQ0FBK0M7QUFDL0Msb0NBQW9DO0FBQ3BDLCtDQUErQztBQUMvQyxzQ0FBOEI7QUFFOUIsTUFBTSxFQUFFLEtBQUssRUFBRSxHQUFHLGdCQUFNLENBQUE7QUFFeEIsVUFBVTtBQUNWLDBEQUEwRDtBQUMxRCxtQkFBOEIsR0FBWSxFQUFFLElBQXdCOztRQUNsRSxNQUFNLEVBQUUsSUFBSSxFQUFFLEdBQUcsR0FBRyxDQUFBO1FBQ3BCLE1BQU0sTUFBTSxHQUFHLE1BQU0sQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLENBQUE7UUFDakMsS0FBSyxNQUFNLEtBQUssSUFBSSxNQUFNLEVBQUU7WUFDMUIsSUFBSSxJQUFJLENBQUMsVUFBVSxDQUFDLEtBQUssQ0FBQyxJQUFJLFlBQVksQ0FBQyxLQUFLLENBQUMsQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLEVBQUU7Z0JBQzVELE1BQU0sR0FBRyxDQUFDLEtBQUssQ0FBQyxLQUFLLENBQUMsS0FBSyxDQUFDLENBQUMsQ0FBQyxDQUFDLEdBQUcsRUFBRSxJQUFJLENBQUMsQ0FBQTtnQkFDekMsTUFBSzthQUNOO1NBQ0Y7UUFDRCxNQUFNLElBQUksRUFBRSxDQUFBO0lBQ2QsQ0FBQztDQUFBO0FBVkQsNEJBVUMifQ==