forked from justjavac/proxy-www
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
26 lines (26 loc) · 890 Bytes
/
index.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
const www = new Proxy(() => 'https://www', {
get(target, key, proxy) {
if (typeof key === 'string') {
return new Proxy(() => target() + '.' + key, this);
}
if (key === Symbol.toPrimitive) {
return () => target() + '/';
}
return Reflect.get(target, key, proxy);
},
apply(target, thisArg, args) {
switch (typeof args[0]) {
case 'function':
return fetch(target().replace(/\.then$/, '')).then(...args);
case 'object':
args = [ String.raw(...args) ];
case 'string':
return {
[Symbol.toPrimitive]: () => target() + '/' + arg[0],
then: (v, x) => fetch(target() + '/' + arg[0]).then(v, x),
};
default:
return target() + '/';
}
},
});