zcatalyst-cli
Version:
Command Line Tool for CATALYST
16 lines (15 loc) • 551 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = (req, res, next) => {
const bestRule = res.locals.bestRule;
let finalUrl = bestRule.target_endpoint;
for (const [key, value] of Object.entries(bestRule.params)) {
finalUrl = finalUrl === null || finalUrl === void 0 ? void 0 : finalUrl.replace(`{${key}}`, value);
}
const queryIdx = req.url.indexOf('?');
if (queryIdx > 0) {
finalUrl = finalUrl + req.url.slice(queryIdx);
}
req.url = finalUrl;
next();
};