You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
604 B
JavaScript

#!/usr/bin/node
import Koa from "koa";
import Router from "@koa/router";
import axios from "axios";
const router = new Router();
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) {
const origin = new URL(url).origin;
response.data = response.data.replace(href_regex, `href="${origin}/`);
}
ctx.body = response.data;
});
const app = new Koa();
app.use(router.routes());
app.listen(8383);
console.log("Listening on port 8383");