Fix rewrite

master
Kuba Orlik 3 years ago
parent 6799b7492a
commit 1cfd7dff63

@ -6,15 +6,18 @@ import axios from "axios";
const router = new Router();
const href_regex = /href="\/"/g;
const href_regex = /href="\//g;
router.get("/", async (ctx) => {
const url = ctx.query.url;
const rewrite = ctx.query.url;
const response = await axios.get(url);
if (response.data.replace && rewrite) {
console.log("replacing!");
const origin = new URL(url).origin;
console.log("origin", origin);
response.data = response.data.replace(href_regex, `href="${origin}/`);
console.log("new response.data", response.data);
}
ctx.body = response.data;
});

Loading…
Cancel
Save