Add open proxy script

This commit is contained in:
Pieter Vander Vennet 2024-06-10 14:54:31 +02:00
parent 662d58d58f
commit 043c9a1d7d

33
scripts/openProxy.ts Normal file
View file

@ -0,0 +1,33 @@
import Script from "./Script"
import { Server } from "./server"
import ScriptUtils from "./ScriptUtils"
class OpenProxy extends Script{
constructor() {
super("Allows any MapComplete-related domain to access the open internet via the proxy. No caching is done")
}
async main(args: string[]): Promise<void> {
new Server(1237,{
},[
{
mustMatch: "json",
mimetype: "application/json",
handle: async (_, params) => {
const url = decodeURIComponent(params.get("url"))
let content = await ScriptUtils.Download(url)
while(content["redirect"]){
content = await ScriptUtils.Download(content["redirect"])
}
return content["content"]
}
}
])
}
}
new OpenProxy().run()