|
|
|
@ -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;
|
|
|
|
|
});
|
|
|
|
|