chemicaljs 1.6.7 → 1.7.0

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/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Chemical
2
2
  Easily create your own web proxy with no experience required.
3
3
 
4
+ > [!IMPORTANT]
5
+ > I am in the process of creating a documentation site. These docs might be outdated.
6
+
4
7
  ## Setup
5
8
 
6
9
  A simple example can be found in [`/example/`](https://github.com/chemicaljs/chemical/tree/main/examples/example).
@@ -25,13 +28,13 @@ Create a new Node.js project and create a script file for the server.
25
28
  ```js
26
29
  import { ChemicalServer } from "chemicaljs";
27
30
 
28
- const chemical = new ChemicalServer();
31
+ const [app, listen] = new ChemicalServer();
29
32
  ```
30
33
 
31
34
  You can pass options to disable proxy services and set the default service.
32
35
 
33
36
  ```js
34
- const chemical = new ChemicalServer({
37
+ const [app, listen] = new ChemicalServer({
35
38
  default: "rammerhead",
36
39
  uv: true,
37
40
  scramjet: false,
@@ -43,7 +46,7 @@ const chemical = new ChemicalServer({
43
46
 
44
47
  `hostname_whitelist` overrides `hostname_blacklist` if you try to set them both.
45
48
 
46
- 3. Use `chemical.app` which is an express app. `chemical.use` is shortand for `chemical.app.use` (same with `chemical.get`). You may need to import express for certain APIs.
49
+ 3. Use `app` which is an express app. You may need to import express for certain APIs.
47
50
 
48
51
  ```js
49
52
  chemical.get("/", function(req, res){
@@ -51,20 +54,21 @@ chemical.get("/", function(req, res){
51
54
  });
52
55
  ```
53
56
 
57
+ 4. Use `app.serveChemical()` to serve Chemical routes.
54
58
 
55
- 5. Chemical routes are after user routes as to not overwrite custom files. Due to this you will need to use `chemical.error` for custom error pages.
59
+ 5. Use `serveChemical` after main routes but before 404 routes. Example 404 page.
56
60
 
57
61
  ```js
58
- chemical.error((req, res) => {
62
+ app.use((req, res) => {
59
63
  res.status(404);
60
64
  res.send("404 Error");
61
65
  });
62
66
  ```
63
67
 
64
- 4. Use `chemical.listen` on a port of your choosing.
68
+ 4. Use `listen` on a port of your choosing.
65
69
 
66
70
  ```js
67
- chemical.listen(3000);
71
+ listen(3000);
68
72
  ```
69
73
 
70
74
  Below is an example of a simple backend. This example will setup Chemical and serve the "public" folder along with the `index.html` file as `/` and `.html` files without the extension.
@@ -74,20 +78,22 @@ Below is an example of a simple backend. This example will setup Chemical and se
74
78
  import { ChemicalServer } from "chemicaljs";
75
79
  import express from "express";
76
80
 
77
- const chemical = new ChemicalServer();
81
+ const [app, listen] = new ChemicalServer();
78
82
  const port = process.env.PORT || 3000;
79
83
 
80
- chemical.use(express.static("public", {
84
+ app.use(express.static("public", {
81
85
  index: "index.html",
82
86
  extensions: ["html"]
83
87
  }));
84
88
 
85
- chemical.error((req, res) => {
89
+ app.serveChemical();
90
+
91
+ app.use((req, res) => {
86
92
  res.status(404);
87
93
  res.send("404 Error");
88
94
  });
89
95
 
90
- chemical.listen(port, () => {
96
+ listen(port, () => {
91
97
  console.log(`Chemical demo listening on port ${port}`);
92
98
  });
93
99
  ```
@@ -150,22 +156,40 @@ If you want to set the transport just change the `transport` attribute. Choose `
150
156
  <script data-transport="epoxy" src="/chemical.js"></script>
151
157
  ```
152
158
 
153
- 2. In a inline script or javascript file, encode a URL with Chemical using the async function `window.chemicalEncode`.
159
+ 2. In a inline script or javascript file, encode a URL with Chemical using the async function `chemical.encode`.
154
160
 
155
161
  ```js
156
- await window.chemicalEncode("https://example.com")
162
+ await chemical.encode("https://example.com")
157
163
  ```
158
164
 
159
165
  Optional: Change service to `uv`, `scramjet`, or `rammerhead`. Defaults to `uv` or server option.
160
166
 
161
167
  ```js
162
- await window.chemicalEncode("https://example.com", "rammerhead")
168
+ await chemical.encode("https://example.com", {
169
+ service: "rammerhead"
170
+ })
171
+ ```
172
+
173
+ 4. Set `autoHttps` to make `example.com` > `https://example.com`
174
+
175
+ ```js
176
+ await chemical.encode("example.com", {
177
+ autoHttps: true
178
+ })
163
179
  ```
164
180
 
165
- 3. You may want to check if Chemical has loaded before encoding a URL.
181
+ 5. Use a search engine with the `searchEngine` property. Use a search engine URL with "%s" in place of query.
166
182
 
167
183
  ```js
168
- if (window.chemicalLoaded) {
184
+ await chemical.encode("cheese", {
185
+ searchEngine: "https://www.google.com/search?q=%s"
186
+ })
187
+ ```
188
+
189
+ 6. You may want to check if Chemical has loaded before encoding a URL.
190
+
191
+ ```js
192
+ if (window.chemical.loaded) {
169
193
  //Chemical is loaded
170
194
  }
171
195
  ```
@@ -176,10 +200,16 @@ window.addEventListener("chemicalLoaded", function(e) {
176
200
  });
177
201
  ```
178
202
 
179
- 4. Change the transport and Wisp URL with `chemicalTransport`
203
+ 7. Change the transport with `chemical.setTransport`
180
204
 
181
205
  ```js
182
- await chemicalTransport("libcurl", "wss://wisp.mercurywork.shop/")
206
+ await chemical.setTransport("libcurl") //libcurl or epoxy
207
+ ```
208
+
209
+ 8. Change the Wisp URL with `chemical.setWisp`
210
+
211
+ ```js
212
+ await chemical.setWisp("wss://wisp.mercurywork.shop/")
183
213
  ```
184
214
 
185
215
  Below is a simple example of a simple input that redirects to the encoded URL when the user presses enter. It checks if there is any input and if Chemical has loaded before loading.
@@ -193,8 +223,8 @@ Below is a simple example of a simple input that redirects to the encoded URL wh
193
223
  const search = document.getElementById("search");
194
224
 
195
225
  search.addEventListener("keydown", async function (e) {
196
- if (e.key == "Enter" && window.chemicalLoaded && e.target.value) {
197
- window.location = await window.chemicalEncode(e.target.value)
226
+ if (e.key == "Enter" && chemical.loaded && e.target.value) {
227
+ window.location = await chemical.encode(e.target.value)
198
228
  }
199
229
  })
200
230
  </script>
@@ -321,13 +351,5 @@ Set the second parameter of `chemicalAction` to the `id` of the iframe.
321
351
  <iframe controls="my-controls-2" id="my-iframe-2" is="chemical-iframe"></iframe>
322
352
  ```
323
353
 
324
- ## Future Additions
325
-
326
- - Automatically add https:// if needed
327
- - Search engine option for search
328
- - Easy tab cloaking
329
- - Easy about:blank
330
- - Proxy switcher/searchengine switcher/cloak switcher
331
-
332
354
  ## License
333
355
  Chemical uses the AGPL 3.0 license.
@@ -1,4 +1,8 @@
1
- window.chemicalLoaded = false;
1
+ window.chemical = {
2
+ loaded: false,
3
+ transport: document.currentScript.dataset.transport || "libcurl",
4
+ wisp: document.currentScript.dataset.wisp || (location.protocol === "https:" ? "wss" : "ws") + "://" + location.host + "/wisp/"
5
+ }
2
6
 
3
7
  function rammerheadEncode(baseUrl) {
4
8
  const mod = (n, m) => ((n % m) + m) % m
@@ -174,7 +178,7 @@ function rammerheadEncode(baseUrl) {
174
178
  })
175
179
  }
176
180
 
177
- async function chemicalEncode(url, service = defaultService) {
181
+ async function encodeService(url, service) {
178
182
  switch (service) {
179
183
  case "uv":
180
184
  if (uvEnabled) {
@@ -193,7 +197,7 @@ async function chemicalEncode(url, service = defaultService) {
193
197
  case "scramjet":
194
198
  if (scramjetEnabled) {
195
199
  return (
196
- window.location.origin +
200
+ "https://proxysite.com" +
197
201
  window.__scramjet$config.prefix +
198
202
  window.__scramjet$config.codec.encode(url)
199
203
  );
@@ -202,8 +206,28 @@ async function chemicalEncode(url, service = defaultService) {
202
206
  }
203
207
  }
204
208
 
209
+ window.chemical.encode = async function (url, config) {
210
+ if (!config || typeof config !== "object" || Array.isArray(config)) {
211
+ config = {
212
+ service: defaultService,
213
+ autoHttps: false
214
+ }
215
+ }
216
+
217
+ if (url.match(/^https?:\/\//)) {
218
+ return await encodeService(url, config.service);
219
+ } else if (config.autoHttps == true && (url.includes(".") && !url.includes(" "))) {
220
+ return await encodeService("https://" + url, config.service);
221
+ } else if (config.searchEngine) {
222
+ return await encodeService(config.searchEngine.replace("%s", encodeURIComponent(url)), config.service);
223
+ } else {
224
+ return await encodeService(url, config.service);
225
+ }
226
+ }
227
+
205
228
  function getTransport(transport) {
206
229
  switch (transport) {
230
+ default:
207
231
  case "libcurl":
208
232
  return "/libcurl/index.mjs"
209
233
  break;
@@ -213,19 +237,17 @@ function getTransport(transport) {
213
237
  }
214
238
  }
215
239
 
216
- let connection;
217
-
218
- let wispURL = document.currentScript.dataset.wisp;
219
- let transport = document.currentScript.dataset.transport;
240
+ window.chemical.setTransport = async function (newTransport = window.chemical.transport) {
241
+ await window.chemical.connection.setTransport(getTransport(newTransport), [{ wisp: window.chemical.wisp }]);
242
+ window.chemical.transport = newTransport;
243
+ }
220
244
 
221
- async function chemicalTransport(newTransport = transport, wisp = wispURL) {
222
- await connection.setTransport(getTransport(newTransport) || "/libcurl/index.mjs", [{ wisp: wisp || (location.protocol === "https:" ? "wss" : "ws") + "://" + location.host + "/wisp/" }]);
245
+ window.chemical.setWisp = async function (wisp = window.chemical.wisp) {
246
+ await window.chemical.connection.setTransport(getTransport(window.chemical.transport), [{ wisp: wisp }]);
247
+ window.chemical.wisp = wisp;
223
248
  }
224
249
 
225
250
  async function registerSW() {
226
- connection = new window.BareMux.BareMuxConnection("/baremux/worker.js");
227
- await chemicalTransport();
228
-
229
251
  if ("serviceWorker" in navigator) {
230
252
  await navigator.serviceWorker.register("/chemical.sw.js");
231
253
  } else {
@@ -247,6 +269,28 @@ async function loadScript(src) {
247
269
  });
248
270
  }
249
271
 
272
+ function setupFetch() {
273
+ const client = new window.BareMux.BareClient();
274
+ window.chemical.fetch = client.fetch.bind(client);
275
+
276
+ window.chemical.getSuggestions = async function (query) {
277
+ if (!query) {
278
+ return [];
279
+ }
280
+
281
+ try {
282
+ const DDGSuggestions = await window.chemical.fetch(
283
+ "https://duckduckgo.com/ac/?q=" + query + "&type=list"
284
+ );
285
+ const suggestions = await DDGSuggestions.json();
286
+ return suggestions[1].slice(0, 9);
287
+ } catch (err) {
288
+ console.error(err);
289
+ return [];
290
+ }
291
+ }
292
+ }
293
+
250
294
  (async () => {
251
295
  await loadScript("/baremux/index.js");
252
296
  if (uvEnabled) {
@@ -257,7 +301,10 @@ async function loadScript(src) {
257
301
  await loadScript("/scramjet/scramjet.codecs.js");
258
302
  await loadScript("/scramjet/scramjet.config.js");
259
303
  }
304
+ window.chemical.connection = new window.BareMux.BareMuxConnection("/baremux/worker.js");
305
+ await window.chemical.setTransport();
306
+ setupFetch();
260
307
  await registerSW();
261
- chemicalLoaded = true;
308
+ window.chemical.loaded = true;
262
309
  window.dispatchEvent(new Event("chemicalLoaded"));
263
310
  })();
@@ -1,19 +1,21 @@
1
1
  import { ChemicalServer } from "chemicaljs";
2
2
  import express from "express";
3
3
 
4
- const chemical = new ChemicalServer();
4
+ const [app, listen] = new ChemicalServer();
5
5
  const port = process.env.PORT || 3000;
6
6
 
7
- chemical.use(express.static("public", {
7
+ app.use(express.static("public", {
8
8
  index: "index.html",
9
9
  extensions: ["html"]
10
10
  }));
11
11
 
12
- chemical.error((req, res) => {
12
+ app.serveChemical();
13
+
14
+ app.use((req, res) => {
13
15
  res.status(404);
14
16
  res.send("404 Error");
15
17
  });
16
18
 
17
- chemical.listen(port, () => {
19
+ listen(port, () => {
18
20
  console.log(`Chemical example listening on port ${port}`);
19
21
  });
@@ -9,7 +9,7 @@
9
9
  "version": "1.0.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
- "chemicaljs": "^1.6.6",
12
+ "chemicaljs": "^1.6.7",
13
13
  "express": "^4.19.2"
14
14
  }
15
15
  },
@@ -409,16 +409,16 @@
409
409
  "integrity": "sha512-Y5jByKQ/5ZhyKd3adHUQ18nB+HOUpopxRXIJh6KHXEq4rkG2AazHyMm42dvtAxHvkKlHkLxR7/5oxKZSD6rE4A=="
410
410
  },
411
411
  "node_modules/@mercuryworkshop/epoxy-tls": {
412
- "version": "2.1.0-1",
413
- "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-tls/-/epoxy-tls-2.1.0-1.tgz",
414
- "integrity": "sha512-vyC2xVEd3gUl00r3CxqVd7qOe0FrkZQT2l6EP0qohqzcwV6oDq27nAa/I/gceYl38lDiqatxEoKKO4okvNbKCw=="
412
+ "version": "2.1.2-1",
413
+ "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-tls/-/epoxy-tls-2.1.2-1.tgz",
414
+ "integrity": "sha512-qt6UOEZcVMYblFwOKaNAZHoDHSYN3JZ5Z6BvRHKB6zo1DFMub+cPuYQ+Aauib7LmIabYWZi2cMyfO5VsNLDYoA=="
415
415
  },
416
416
  "node_modules/@mercuryworkshop/epoxy-transport": {
417
- "version": "2.1.5",
418
- "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-transport/-/epoxy-transport-2.1.5.tgz",
419
- "integrity": "sha512-e4XTHaIK2BEPolhfZmn4OLK9kS4DjnpfzGSazc0yiMMm7j7G2RwevUOp/wO83TkV5jOZdC4O79iaDvFWdDIRuw==",
417
+ "version": "2.1.8",
418
+ "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-transport/-/epoxy-transport-2.1.8.tgz",
419
+ "integrity": "sha512-quBpEDb3mRxQOl7S6NkT6qFoII+cmBVNOC9/58hN7A4WIg6Q11d+FgAygDLWq5yESgtmDKujZjBVA2XQ6OkLgQ==",
420
420
  "dependencies": {
421
- "@mercuryworkshop/epoxy-tls": "2.1.0-1"
421
+ "@mercuryworkshop/epoxy-tls": "2.1.2-1"
422
422
  }
423
423
  },
424
424
  "node_modules/@mercuryworkshop/libcurl-transport": {
@@ -1163,12 +1163,12 @@
1163
1163
  }
1164
1164
  },
1165
1165
  "node_modules/chemicaljs": {
1166
- "version": "1.6.6",
1167
- "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.6.tgz",
1168
- "integrity": "sha512-Efih9ve2ezQDdqHeISb//ARLzZAiH1AtRvi3XE6vCaBddvelSKDLoclXLkYtV5rZ2ovlthWakRfP5MbrZOQuSA==",
1166
+ "version": "1.6.7",
1167
+ "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.7.tgz",
1168
+ "integrity": "sha512-3BaUpDAaHRD4GiE3MVfJ1cB0lxWx4cojOs/XN3SePmfm96DGjjvWEEpSikoC97yJe2XrNi7JLtASTB1Dk4af9g==",
1169
1169
  "dependencies": {
1170
1170
  "@mercuryworkshop/bare-mux": "^2.0.4",
1171
- "@mercuryworkshop/epoxy-transport": "^2.1.5",
1171
+ "@mercuryworkshop/epoxy-transport": "^2.1.8",
1172
1172
  "@mercuryworkshop/libcurl-transport": "^1.3.7",
1173
1173
  "@mercuryworkshop/scramjet": "^1.0.2",
1174
1174
  "@mercuryworkshop/wisp-js": "^0.1.1",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "homepage": "https://github.com/chemicaljs/chemical#readme",
20
20
  "dependencies": {
21
- "chemicaljs": "^1.6.6",
21
+ "chemicaljs": "^1.6.7",
22
22
  "express": "^4.19.2"
23
23
  }
24
24
  }
@@ -9,7 +9,7 @@
9
9
  "version": "1.0.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
- "chemicaljs": "^1.6.6",
12
+ "chemicaljs": "^1.6.7",
13
13
  "express": "^4.19.2"
14
14
  }
15
15
  },
@@ -409,16 +409,16 @@
409
409
  "integrity": "sha512-Y5jByKQ/5ZhyKd3adHUQ18nB+HOUpopxRXIJh6KHXEq4rkG2AazHyMm42dvtAxHvkKlHkLxR7/5oxKZSD6rE4A=="
410
410
  },
411
411
  "node_modules/@mercuryworkshop/epoxy-tls": {
412
- "version": "2.1.0-1",
413
- "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-tls/-/epoxy-tls-2.1.0-1.tgz",
414
- "integrity": "sha512-vyC2xVEd3gUl00r3CxqVd7qOe0FrkZQT2l6EP0qohqzcwV6oDq27nAa/I/gceYl38lDiqatxEoKKO4okvNbKCw=="
412
+ "version": "2.1.2-1",
413
+ "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-tls/-/epoxy-tls-2.1.2-1.tgz",
414
+ "integrity": "sha512-qt6UOEZcVMYblFwOKaNAZHoDHSYN3JZ5Z6BvRHKB6zo1DFMub+cPuYQ+Aauib7LmIabYWZi2cMyfO5VsNLDYoA=="
415
415
  },
416
416
  "node_modules/@mercuryworkshop/epoxy-transport": {
417
- "version": "2.1.5",
418
- "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-transport/-/epoxy-transport-2.1.5.tgz",
419
- "integrity": "sha512-e4XTHaIK2BEPolhfZmn4OLK9kS4DjnpfzGSazc0yiMMm7j7G2RwevUOp/wO83TkV5jOZdC4O79iaDvFWdDIRuw==",
417
+ "version": "2.1.8",
418
+ "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-transport/-/epoxy-transport-2.1.8.tgz",
419
+ "integrity": "sha512-quBpEDb3mRxQOl7S6NkT6qFoII+cmBVNOC9/58hN7A4WIg6Q11d+FgAygDLWq5yESgtmDKujZjBVA2XQ6OkLgQ==",
420
420
  "dependencies": {
421
- "@mercuryworkshop/epoxy-tls": "2.1.0-1"
421
+ "@mercuryworkshop/epoxy-tls": "2.1.2-1"
422
422
  }
423
423
  },
424
424
  "node_modules/@mercuryworkshop/libcurl-transport": {
@@ -1163,12 +1163,12 @@
1163
1163
  }
1164
1164
  },
1165
1165
  "node_modules/chemicaljs": {
1166
- "version": "1.6.6",
1167
- "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.6.tgz",
1168
- "integrity": "sha512-Efih9ve2ezQDdqHeISb//ARLzZAiH1AtRvi3XE6vCaBddvelSKDLoclXLkYtV5rZ2ovlthWakRfP5MbrZOQuSA==",
1166
+ "version": "1.6.7",
1167
+ "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.7.tgz",
1168
+ "integrity": "sha512-3BaUpDAaHRD4GiE3MVfJ1cB0lxWx4cojOs/XN3SePmfm96DGjjvWEEpSikoC97yJe2XrNi7JLtASTB1Dk4af9g==",
1169
1169
  "dependencies": {
1170
1170
  "@mercuryworkshop/bare-mux": "^2.0.4",
1171
- "@mercuryworkshop/epoxy-transport": "^2.1.5",
1171
+ "@mercuryworkshop/epoxy-transport": "^2.1.8",
1172
1172
  "@mercuryworkshop/libcurl-transport": "^1.3.7",
1173
1173
  "@mercuryworkshop/scramjet": "^1.0.2",
1174
1174
  "@mercuryworkshop/wisp-js": "^0.1.1",
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "homepage": "https://github.com/chemicaljs/chemical#readme",
21
21
  "dependencies": {
22
- "chemicaljs": "^1.6.6",
22
+ "chemicaljs": "^1.6.7",
23
23
  "express": "^4.19.2"
24
24
  }
25
25
  }
@@ -1,14 +1,16 @@
1
1
  import { ChemicalServer } from "chemicaljs";
2
2
  import express from "express";
3
3
 
4
- const chemical = new ChemicalServer();
4
+ const [app, listen] = new ChemicalServer();
5
5
  const port = process.env.PORT || 3000;
6
6
 
7
- chemical.use(express.static("public", {
7
+ app.use(express.static("public", {
8
8
  index: "index.html",
9
9
  extensions: ["html"]
10
10
  }));
11
11
 
12
- chemical.listen(port, () => {
12
+ app.serveChemical();
13
+
14
+ listen(port, () => {
13
15
  console.log(`Chemical example components listening on port ${port}`);
14
16
  });
@@ -9,7 +9,7 @@
9
9
  "version": "1.0.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
- "chemicaljs": "^1.6.6",
12
+ "chemicaljs": "^1.6.7",
13
13
  "express": "^4.19.2"
14
14
  }
15
15
  },
@@ -409,16 +409,16 @@
409
409
  "integrity": "sha512-Y5jByKQ/5ZhyKd3adHUQ18nB+HOUpopxRXIJh6KHXEq4rkG2AazHyMm42dvtAxHvkKlHkLxR7/5oxKZSD6rE4A=="
410
410
  },
411
411
  "node_modules/@mercuryworkshop/epoxy-tls": {
412
- "version": "2.1.0-1",
413
- "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-tls/-/epoxy-tls-2.1.0-1.tgz",
414
- "integrity": "sha512-vyC2xVEd3gUl00r3CxqVd7qOe0FrkZQT2l6EP0qohqzcwV6oDq27nAa/I/gceYl38lDiqatxEoKKO4okvNbKCw=="
412
+ "version": "2.1.2-1",
413
+ "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-tls/-/epoxy-tls-2.1.2-1.tgz",
414
+ "integrity": "sha512-qt6UOEZcVMYblFwOKaNAZHoDHSYN3JZ5Z6BvRHKB6zo1DFMub+cPuYQ+Aauib7LmIabYWZi2cMyfO5VsNLDYoA=="
415
415
  },
416
416
  "node_modules/@mercuryworkshop/epoxy-transport": {
417
- "version": "2.1.5",
418
- "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-transport/-/epoxy-transport-2.1.5.tgz",
419
- "integrity": "sha512-e4XTHaIK2BEPolhfZmn4OLK9kS4DjnpfzGSazc0yiMMm7j7G2RwevUOp/wO83TkV5jOZdC4O79iaDvFWdDIRuw==",
417
+ "version": "2.1.8",
418
+ "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-transport/-/epoxy-transport-2.1.8.tgz",
419
+ "integrity": "sha512-quBpEDb3mRxQOl7S6NkT6qFoII+cmBVNOC9/58hN7A4WIg6Q11d+FgAygDLWq5yESgtmDKujZjBVA2XQ6OkLgQ==",
420
420
  "dependencies": {
421
- "@mercuryworkshop/epoxy-tls": "2.1.0-1"
421
+ "@mercuryworkshop/epoxy-tls": "2.1.2-1"
422
422
  }
423
423
  },
424
424
  "node_modules/@mercuryworkshop/libcurl-transport": {
@@ -1163,12 +1163,12 @@
1163
1163
  }
1164
1164
  },
1165
1165
  "node_modules/chemicaljs": {
1166
- "version": "1.6.6",
1167
- "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.6.tgz",
1168
- "integrity": "sha512-Efih9ve2ezQDdqHeISb//ARLzZAiH1AtRvi3XE6vCaBddvelSKDLoclXLkYtV5rZ2ovlthWakRfP5MbrZOQuSA==",
1166
+ "version": "1.6.7",
1167
+ "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.7.tgz",
1168
+ "integrity": "sha512-3BaUpDAaHRD4GiE3MVfJ1cB0lxWx4cojOs/XN3SePmfm96DGjjvWEEpSikoC97yJe2XrNi7JLtASTB1Dk4af9g==",
1169
1169
  "dependencies": {
1170
1170
  "@mercuryworkshop/bare-mux": "^2.0.4",
1171
- "@mercuryworkshop/epoxy-transport": "^2.1.5",
1171
+ "@mercuryworkshop/epoxy-transport": "^2.1.8",
1172
1172
  "@mercuryworkshop/libcurl-transport": "^1.3.7",
1173
1173
  "@mercuryworkshop/scramjet": "^1.0.2",
1174
1174
  "@mercuryworkshop/wisp-js": "^0.1.1",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "homepage": "https://github.com/chemicaljs/chemical#readme",
20
20
  "dependencies": {
21
- "chemicaljs": "^1.6.6",
21
+ "chemicaljs": "^1.6.7",
22
22
  "express": "^4.19.2"
23
23
  }
24
24
  }
@@ -1,14 +1,16 @@
1
1
  import { ChemicalServer } from "chemicaljs";
2
2
  import express from "express";
3
3
 
4
- const chemical = new ChemicalServer();
4
+ const [app, listen] = new ChemicalServer();
5
5
  const port = process.env.PORT || 3000;
6
6
 
7
- chemical.use(express.static("public", {
7
+ app.use(express.static("public", {
8
8
  index: "index.html",
9
9
  extensions: ["html"]
10
10
  }));
11
11
 
12
- chemical.listen(port, () => {
12
+ app.serveChemical();
13
+
14
+ listen(port, () => {
13
15
  console.log(`Chemical example styled listening on port ${port}`);
14
16
  });
@@ -9,7 +9,7 @@
9
9
  "version": "1.0.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
- "chemicaljs": "^1.6.6",
12
+ "chemicaljs": "^1.6.7",
13
13
  "express": "^4.19.2"
14
14
  }
15
15
  },
@@ -409,16 +409,16 @@
409
409
  "integrity": "sha512-Y5jByKQ/5ZhyKd3adHUQ18nB+HOUpopxRXIJh6KHXEq4rkG2AazHyMm42dvtAxHvkKlHkLxR7/5oxKZSD6rE4A=="
410
410
  },
411
411
  "node_modules/@mercuryworkshop/epoxy-tls": {
412
- "version": "2.1.0-1",
413
- "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-tls/-/epoxy-tls-2.1.0-1.tgz",
414
- "integrity": "sha512-vyC2xVEd3gUl00r3CxqVd7qOe0FrkZQT2l6EP0qohqzcwV6oDq27nAa/I/gceYl38lDiqatxEoKKO4okvNbKCw=="
412
+ "version": "2.1.2-1",
413
+ "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-tls/-/epoxy-tls-2.1.2-1.tgz",
414
+ "integrity": "sha512-qt6UOEZcVMYblFwOKaNAZHoDHSYN3JZ5Z6BvRHKB6zo1DFMub+cPuYQ+Aauib7LmIabYWZi2cMyfO5VsNLDYoA=="
415
415
  },
416
416
  "node_modules/@mercuryworkshop/epoxy-transport": {
417
- "version": "2.1.5",
418
- "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-transport/-/epoxy-transport-2.1.5.tgz",
419
- "integrity": "sha512-e4XTHaIK2BEPolhfZmn4OLK9kS4DjnpfzGSazc0yiMMm7j7G2RwevUOp/wO83TkV5jOZdC4O79iaDvFWdDIRuw==",
417
+ "version": "2.1.8",
418
+ "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-transport/-/epoxy-transport-2.1.8.tgz",
419
+ "integrity": "sha512-quBpEDb3mRxQOl7S6NkT6qFoII+cmBVNOC9/58hN7A4WIg6Q11d+FgAygDLWq5yESgtmDKujZjBVA2XQ6OkLgQ==",
420
420
  "dependencies": {
421
- "@mercuryworkshop/epoxy-tls": "2.1.0-1"
421
+ "@mercuryworkshop/epoxy-tls": "2.1.2-1"
422
422
  }
423
423
  },
424
424
  "node_modules/@mercuryworkshop/libcurl-transport": {
@@ -1163,12 +1163,12 @@
1163
1163
  }
1164
1164
  },
1165
1165
  "node_modules/chemicaljs": {
1166
- "version": "1.6.6",
1167
- "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.6.tgz",
1168
- "integrity": "sha512-Efih9ve2ezQDdqHeISb//ARLzZAiH1AtRvi3XE6vCaBddvelSKDLoclXLkYtV5rZ2ovlthWakRfP5MbrZOQuSA==",
1166
+ "version": "1.6.7",
1167
+ "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.7.tgz",
1168
+ "integrity": "sha512-3BaUpDAaHRD4GiE3MVfJ1cB0lxWx4cojOs/XN3SePmfm96DGjjvWEEpSikoC97yJe2XrNi7JLtASTB1Dk4af9g==",
1169
1169
  "dependencies": {
1170
1170
  "@mercuryworkshop/bare-mux": "^2.0.4",
1171
- "@mercuryworkshop/epoxy-transport": "^2.1.5",
1171
+ "@mercuryworkshop/epoxy-transport": "^2.1.8",
1172
1172
  "@mercuryworkshop/libcurl-transport": "^1.3.7",
1173
1173
  "@mercuryworkshop/scramjet": "^1.0.2",
1174
1174
  "@mercuryworkshop/wisp-js": "^0.1.1",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "homepage": "https://github.com/chemicaljs/chemical#readme",
20
20
  "dependencies": {
21
- "chemicaljs": "^1.6.6",
21
+ "chemicaljs": "^1.6.7",
22
22
  "express": "^4.19.2"
23
23
  }
24
24
  }
@@ -1,14 +1,16 @@
1
1
  import { ChemicalServer } from "chemicaljs";
2
2
  import express from "express";
3
3
 
4
- const chemical = new ChemicalServer();
4
+ const [app, listen] = new ChemicalServer();
5
5
  const port = process.env.PORT || 3000;
6
6
 
7
- chemical.use(express.static("dist", {
7
+ app.use(express.static("dist", {
8
8
  index: "index.html",
9
9
  extensions: ["html"]
10
10
  }));
11
11
 
12
- chemical.listen(port, () => {
12
+ app.serveChemical();
13
+
14
+ listen(port, () => {
13
15
  console.log(`Chemical example vite listening on port ${port}`);
14
16
  });
@@ -6,7 +6,7 @@
6
6
  "": {
7
7
  "name": "chemical-example-vite",
8
8
  "dependencies": {
9
- "chemicaljs": "^1.6.6",
9
+ "chemicaljs": "^1.6.7",
10
10
  "express": "^4.19.2",
11
11
  "preact": "^10.23.2"
12
12
  },
@@ -796,16 +796,16 @@
796
796
  "integrity": "sha512-Y5jByKQ/5ZhyKd3adHUQ18nB+HOUpopxRXIJh6KHXEq4rkG2AazHyMm42dvtAxHvkKlHkLxR7/5oxKZSD6rE4A=="
797
797
  },
798
798
  "node_modules/@mercuryworkshop/epoxy-tls": {
799
- "version": "2.1.0-1",
800
- "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-tls/-/epoxy-tls-2.1.0-1.tgz",
801
- "integrity": "sha512-vyC2xVEd3gUl00r3CxqVd7qOe0FrkZQT2l6EP0qohqzcwV6oDq27nAa/I/gceYl38lDiqatxEoKKO4okvNbKCw=="
799
+ "version": "2.1.2-1",
800
+ "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-tls/-/epoxy-tls-2.1.2-1.tgz",
801
+ "integrity": "sha512-qt6UOEZcVMYblFwOKaNAZHoDHSYN3JZ5Z6BvRHKB6zo1DFMub+cPuYQ+Aauib7LmIabYWZi2cMyfO5VsNLDYoA=="
802
802
  },
803
803
  "node_modules/@mercuryworkshop/epoxy-transport": {
804
- "version": "2.1.5",
805
- "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-transport/-/epoxy-transport-2.1.5.tgz",
806
- "integrity": "sha512-e4XTHaIK2BEPolhfZmn4OLK9kS4DjnpfzGSazc0yiMMm7j7G2RwevUOp/wO83TkV5jOZdC4O79iaDvFWdDIRuw==",
804
+ "version": "2.1.8",
805
+ "resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-transport/-/epoxy-transport-2.1.8.tgz",
806
+ "integrity": "sha512-quBpEDb3mRxQOl7S6NkT6qFoII+cmBVNOC9/58hN7A4WIg6Q11d+FgAygDLWq5yESgtmDKujZjBVA2XQ6OkLgQ==",
807
807
  "dependencies": {
808
- "@mercuryworkshop/epoxy-tls": "2.1.0-1"
808
+ "@mercuryworkshop/epoxy-tls": "2.1.2-1"
809
809
  }
810
810
  },
811
811
  "node_modules/@mercuryworkshop/libcurl-transport": {
@@ -1726,12 +1726,12 @@
1726
1726
  }
1727
1727
  },
1728
1728
  "node_modules/chemicaljs": {
1729
- "version": "1.6.6",
1730
- "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.6.tgz",
1731
- "integrity": "sha512-Efih9ve2ezQDdqHeISb//ARLzZAiH1AtRvi3XE6vCaBddvelSKDLoclXLkYtV5rZ2ovlthWakRfP5MbrZOQuSA==",
1729
+ "version": "1.6.7",
1730
+ "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.7.tgz",
1731
+ "integrity": "sha512-3BaUpDAaHRD4GiE3MVfJ1cB0lxWx4cojOs/XN3SePmfm96DGjjvWEEpSikoC97yJe2XrNi7JLtASTB1Dk4af9g==",
1732
1732
  "dependencies": {
1733
1733
  "@mercuryworkshop/bare-mux": "^2.0.4",
1734
- "@mercuryworkshop/epoxy-transport": "^2.1.5",
1734
+ "@mercuryworkshop/epoxy-transport": "^2.1.8",
1735
1735
  "@mercuryworkshop/libcurl-transport": "^1.3.7",
1736
1736
  "@mercuryworkshop/scramjet": "^1.0.2",
1737
1737
  "@mercuryworkshop/wisp-js": "^0.1.1",
@@ -8,7 +8,7 @@
8
8
  "build": "vite build"
9
9
  },
10
10
  "dependencies": {
11
- "chemicaljs": "^1.6.6",
11
+ "chemicaljs": "^1.6.7",
12
12
  "express": "^4.19.2",
13
13
  "preact": "^10.23.2"
14
14
  },
package/index.js CHANGED
@@ -39,25 +39,13 @@ class ChemicalServer {
39
39
  }
40
40
 
41
41
  this.options = options;
42
-
42
+ this.server = createServer();
43
43
  this.app = express();
44
- this.use = this.app.use.bind(this.app);
45
- this.get = this.app.get.bind(this.app);
46
- this.errorFunctions = [];
47
-
48
- this.error = (newErrorFunction) => {
49
- if (newErrorFunction) {
50
- if (typeof newErrorFunction == "function") {
51
- this.errorFunctions.push(newErrorFunction);
52
- } else {
53
- console.error("Error: Invalid type for Chemical error function.")
54
- }
55
- }
56
- }
57
- }
58
- listen(port, callback) {
59
- const server = createServer();
44
+ this.app.serveChemical = this.serveChemical;
60
45
 
46
+ return [this.app, this.listen]
47
+ }
48
+ serveChemical = () => {
61
49
  const rh = createRammerhead()
62
50
 
63
51
  const rammerheadScopes = [
@@ -138,14 +126,14 @@ class ChemicalServer {
138
126
  this.app.use("/scramjet/", express.static(resolve(__dirname, "config/scramjet")));
139
127
  this.app.use("/scramjet/", express.static(scramjetPath));
140
128
  }
141
- server.on("request", (req, res) => {
129
+ this.server.on("request", (req, res) => {
142
130
  if (this.options.rammerhead && shouldRouteRh(req)) {
143
131
  routeRhRequest(req, res);
144
132
  } else {
145
133
  this.app(req, res);
146
134
  }
147
135
  });
148
- server.on("upgrade", (req, socket, head) => {
136
+ this.server.on("upgrade", (req, socket, head) => {
149
137
  if (req.url && req.url.endsWith("/wisp/")) {
150
138
  if (this.options.hostname_blacklist) {
151
139
  wisp.this.options.hostname_blacklist = this.options.hostname_blacklist
@@ -160,16 +148,9 @@ class ChemicalServer {
160
148
  socket.end();
161
149
  }
162
150
  });
163
-
164
- if (this.errorFunctions.length) {
165
- this.app.use((req, res) => {
166
- for (let errorFunction of this.errorFunctions) {
167
- errorFunction(req, res);
168
- }
169
- });
170
- }
171
-
172
- server.listen(port, callback)
151
+ }
152
+ listen = (port, callback) => {
153
+ this.server.listen(port, callback)
173
154
  }
174
155
  }
175
156
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chemicaljs",
3
- "version": "1.6.7",
3
+ "version": "1.7.0",
4
4
  "description": "Easily create your own web proxy with no experience required.",
5
5
  "repository": {
6
6
  "type": "git",