Try to rewrite the output hrefs

master
Kuba Orlik 3 years ago
parent 5c01c12d3a
commit ff5f3bdffc

@ -13,6 +13,10 @@ then it will listen on port 8383. Then you can make requests like:
`http://localhost:8383/?url=https://duckduckgo.com` `http://localhost:8383/?url=https://duckduckgo.com`
To primitively rewrite relative hrefs to absolute ones:
`http://localhost:8383/?url=https://duckduckgo.com?rewrite=1`
## Install as a daemon ## Install as a daemon
``` ```

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

Loading…
Cancel
Save