nostrudel/server/index.js
hzrd149 289fff2f29 Add REQUEST_PROXY, TOR_PROXY, and I2P_PROXY env options in docker image
Remove CORS_PROXY env option in docker image
2024-04-25 16:59:55 -05:00

53 lines
1.1 KiB
JavaScript

var cors_proxy = require("cors-anywhere");
var { PacProxyAgent } = require("pac-proxy-agent");
const { TOR_PROXY, I2P_PROXY } = process.env;
if (TOR_PROXY) console.log("Tor Proxy:", TOR_PROXY);
if (I2P_PROXY) console.log("I2P Proxy:", I2P_PROXY);
const I2pConfig = I2P_PROXY
? `
if (shExpMatch(host, "*.i2p"))
{
return "PROXY ${I2P_PROXY}";
}`.trim()
: "";
const TorConfig = TOR_PROXY
? `
if (shExpMatch(host, "*.onion"))
{
return "SOCKS5 ${TOR_PROXY}";
}`.trim()
: "";
const PACFile = `
// SPDX-License-Identifier: CC0-1.0
function FindProxyForURL(url, host)
{
${I2pConfig}
${TorConfig}
return "DIRECT";
}
`.trim();
const PACURI = "pac+data:application/x-ns-proxy-autoconfig;base64," + btoa(PACFile);
var host = "127.0.0.1";
var port = 8080;
cors_proxy
.createServer({
requireHeader: [],
removeHeaders: ["cookie", "cookie2"],
redirectSameOrigin: true,
httpProxyOptions: {
xfwd: false,
agent: new PacProxyAgent(PACURI),
},
})
.listen(port, host, () => {
console.log("Running HTTP request proxy on " + host + ":" + port);
});