-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.js
62 lines (54 loc) · 2.23 KB
/
bundle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
/** Optional Chaining literally everything to try and idiot proof this code */
void (async function ProxyServerExample() {
await import("./zglobals.mjs");
const zBuffer = (await import("./zbuffer.mjs"))?.zBuffer;
const zhttp = (await import("./zhttp.mjs"))?.zhttp;
const hostTarget = "www.google.com";
const server = zhttp?.createServer?.();
server?.zlisten?.(3000);
server?.zonRequest?.(async function (req, res) {
Object.assign(req?.headers ?? {}, {
host: hostTarget,
referer: hostTarget,
});
/* start reading the body of the request*/
let body = "";
req?.zonReadable?.(async () => {
body += req?.zread?.();
});
await zawait(
new Promise((resolve) => {
req?.zonEnd?.(resolve);
}),
);
/* finish reading the body of the request*/
/* start copying over the other parts of the request */
const options = {
method: req?.method,
headers: req?.headers,
body: body,
};
/* finish copying over the other parts of the request */
/* fetch from your desired target */
const response = await zfetch?.(
znewURL(`https://${hostTarget}${req.url}`),
options,
);
/* copy over response headers*/
res?.zsetHeaders?.(response?.headers);
res?.zremoveHeader?.("content-length");
res?.zremoveHeader?.("content-encoding");
res?.zremoveHeader?.("x-frame-options");
res?.zgetHeaderNames?.forEach?.((x) => {
if (/security|policy/i?.ztest?.(x)) {
res?.zremoveHeader?.(x);
}
});
/* check to see if the response is not a text format */
/* Copy over target response and return */
const resBody = await response?.zarrayBuffer?.();
res?.zend?.(zBuffer?.zfrom?.(resBody));
});
})();
},{}]},{},[1]);