chemicaljs 1.8.4 → 1.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/chemical.js +39 -0
- package/index.js +45 -8
- package/package.json +1 -1
package/client/chemical.js
CHANGED
|
@@ -304,6 +304,45 @@ window.chemical.decode = async function (url, config) {
|
|
|
304
304
|
}
|
|
305
305
|
};
|
|
306
306
|
|
|
307
|
+
function checkWhitelist(entries, filter) {
|
|
308
|
+
let matched = false;
|
|
309
|
+
for (let entry of entries) {
|
|
310
|
+
if (filter(entry)) {
|
|
311
|
+
matched = true;
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return !matched;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function checkBlacklist(entries, filter) {
|
|
319
|
+
for (let entry of entries) {
|
|
320
|
+
if (filter(entry)) return true;
|
|
321
|
+
}
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
window.chemical.blocked = function (url) {
|
|
326
|
+
let parsedURL;
|
|
327
|
+
try {
|
|
328
|
+
parsedURL = new URL(url);
|
|
329
|
+
} catch {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (hostnameWhitelist.length) {
|
|
334
|
+
return check_whitelist(hostnameWhitelist, (entry) =>
|
|
335
|
+
entry.test(parsedURL.hostname)
|
|
336
|
+
);
|
|
337
|
+
} else if (hostnameBlacklist.length) {
|
|
338
|
+
return checkBlacklist(hostnameBlacklist, (entry) =>
|
|
339
|
+
entry.test(parsedURL.hostname)
|
|
340
|
+
);
|
|
341
|
+
} else {
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
|
|
307
346
|
function getTransport(transport) {
|
|
308
347
|
switch (transport) {
|
|
309
348
|
default:
|
package/index.js
CHANGED
|
@@ -108,6 +108,20 @@ class ChemicalServer {
|
|
|
108
108
|
String(this.options.rammerhead) +
|
|
109
109
|
";\n" +
|
|
110
110
|
chemicalMain;
|
|
111
|
+
chemicalMain =
|
|
112
|
+
"const hostnameBlacklist = [" +
|
|
113
|
+
(this.options.hostname_blacklist
|
|
114
|
+
? this.options.hostname_blacklist.join(", ")
|
|
115
|
+
: "") +
|
|
116
|
+
"];\n" +
|
|
117
|
+
chemicalMain;
|
|
118
|
+
chemicalMain =
|
|
119
|
+
"const hostnameWhitelist = [" +
|
|
120
|
+
(this.options.hostname_whitelist
|
|
121
|
+
? this.options.hostname_whitelist.join(", ")
|
|
122
|
+
: "") +
|
|
123
|
+
"];\n" +
|
|
124
|
+
chemicalMain;
|
|
111
125
|
|
|
112
126
|
chemicalMain = "(async () => {\n" + chemicalMain + "\n})();";
|
|
113
127
|
|
|
@@ -173,12 +187,10 @@ class ChemicalServer {
|
|
|
173
187
|
this.server.on("upgrade", (req, socket, head) => {
|
|
174
188
|
if (req.url && req.url.endsWith("/wisp/")) {
|
|
175
189
|
if (this.options.hostname_blacklist) {
|
|
176
|
-
wisp.this.options.hostname_blacklist
|
|
177
|
-
this.options.hostname_blacklist;
|
|
190
|
+
wisp.options.hostname_blacklist = this.options.hostname_blacklist;
|
|
178
191
|
}
|
|
179
192
|
if (this.options.hostname_whitelist) {
|
|
180
|
-
wisp.this.options.hostname_whitelist
|
|
181
|
-
this.options.hostname_whitelist;
|
|
193
|
+
wisp.options.hostname_whitelist = this.options.hostname_whitelist;
|
|
182
194
|
}
|
|
183
195
|
wisp.routeRequest(req, socket, head);
|
|
184
196
|
} else if (this.options.rammerhead && shouldRouteRh(req)) {
|
|
@@ -263,6 +275,20 @@ const ChemicalVitePlugin = (options) => ({
|
|
|
263
275
|
String(options.rammerhead) +
|
|
264
276
|
";\n" +
|
|
265
277
|
chemicalMain;
|
|
278
|
+
chemicalMain =
|
|
279
|
+
"const hostnameBlacklist = [" +
|
|
280
|
+
(options.hostname_blacklist
|
|
281
|
+
? options.hostname_blacklist.join(", ")
|
|
282
|
+
: "") +
|
|
283
|
+
"];\n" +
|
|
284
|
+
chemicalMain;
|
|
285
|
+
chemicalMain =
|
|
286
|
+
"const hostnameWhitelist = [" +
|
|
287
|
+
(options.hostname_whitelist
|
|
288
|
+
? options.hostname_whitelist.join(", ")
|
|
289
|
+
: "") +
|
|
290
|
+
"];\n" +
|
|
291
|
+
chemicalMain;
|
|
266
292
|
|
|
267
293
|
chemicalMain = "(async () => {\n" + chemicalMain + "\n})();";
|
|
268
294
|
|
|
@@ -283,10 +309,7 @@ const ChemicalVitePlugin = (options) => ({
|
|
|
283
309
|
";\n" +
|
|
284
310
|
chemicalSW;
|
|
285
311
|
chemicalSW =
|
|
286
|
-
"const meteorEnabled = " +
|
|
287
|
-
String(options.meteor) +
|
|
288
|
-
";\n" +
|
|
289
|
-
chemicalSW;
|
|
312
|
+
"const meteorEnabled = " + String(options.meteor) + ";\n" + chemicalSW;
|
|
290
313
|
chemicalSW =
|
|
291
314
|
"const rammerheadEnabled = " +
|
|
292
315
|
String(options.rammerhead) +
|
|
@@ -443,6 +466,20 @@ class ChemicalBuild {
|
|
|
443
466
|
String(this.options.rammerhead) +
|
|
444
467
|
";\n" +
|
|
445
468
|
chemicalMain;
|
|
469
|
+
chemicalMain =
|
|
470
|
+
"const hostnameBlacklist = [" +
|
|
471
|
+
(this.options.hostname_blacklist
|
|
472
|
+
? this.options.hostname_blacklist.join(", ")
|
|
473
|
+
: "") +
|
|
474
|
+
"];\n" +
|
|
475
|
+
chemicalMain;
|
|
476
|
+
chemicalMain =
|
|
477
|
+
"const hostnameWhitelist = [" +
|
|
478
|
+
(this.options.hostname_whitelist
|
|
479
|
+
? this.options.hostname_whitelist.join(", ")
|
|
480
|
+
: "") +
|
|
481
|
+
"];\n" +
|
|
482
|
+
chemicalMain;
|
|
446
483
|
|
|
447
484
|
chemicalMain = "(async () => {\n" + chemicalMain + "\n})();";
|
|
448
485
|
|