chemicaljs 1.6.7 → 1.7.1
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 +58 -28
- package/client/chemical.js +59 -12
- package/examples/example/index.js +6 -4
- package/examples/example/package-lock.json +12 -12
- package/examples/example/package.json +1 -1
- package/examples/example-build/package-lock.json +12 -12
- package/examples/example-build/package.json +1 -1
- package/examples/example-components/index.js +5 -3
- package/examples/example-components/package-lock.json +12 -12
- package/examples/example-components/package.json +1 -1
- package/examples/example-styled/index.js +5 -3
- package/examples/example-styled/package-lock.json +12 -12
- package/examples/example-styled/package.json +1 -1
- package/examples/example-vite/index.js +5 -3
- package/examples/example-vite/package-lock.json +12 -12
- package/examples/example-vite/package.json +1 -1
- package/index.js +10 -29
- package/package.json +1 -1
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
|
|
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
|
|
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 `
|
|
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.
|
|
59
|
+
5. Use `serveChemical` after main routes but before 404 routes. Example 404 page.
|
|
56
60
|
|
|
57
61
|
```js
|
|
58
|
-
|
|
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 `
|
|
68
|
+
4. Use `listen` on a port of your choosing.
|
|
65
69
|
|
|
66
70
|
```js
|
|
67
|
-
|
|
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
|
|
81
|
+
const [app, listen] = new ChemicalServer();
|
|
78
82
|
const port = process.env.PORT || 3000;
|
|
79
83
|
|
|
80
|
-
|
|
84
|
+
app.use(express.static("public", {
|
|
81
85
|
index: "index.html",
|
|
82
86
|
extensions: ["html"]
|
|
83
87
|
}));
|
|
84
88
|
|
|
85
|
-
|
|
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
|
-
|
|
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 `
|
|
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
|
|
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
|
|
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
|
+
})
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
5. Use a search engine with the `searchEngine` property. Use a search engine URL with "%s" in place of query.
|
|
182
|
+
|
|
183
|
+
```js
|
|
184
|
+
await chemical.encode("cheese", {
|
|
185
|
+
searchEngine: "https://www.google.com/search?q=%s"
|
|
186
|
+
})
|
|
163
187
|
```
|
|
164
188
|
|
|
165
|
-
|
|
189
|
+
6. You may want to check if Chemical has loaded before encoding a URL.
|
|
166
190
|
|
|
167
191
|
```js
|
|
168
|
-
if (window.
|
|
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
|
-
|
|
203
|
+
7. Change the transport with `chemical.setTransport`
|
|
204
|
+
|
|
205
|
+
```js
|
|
206
|
+
await chemical.setTransport("libcurl") //libcurl or epoxy
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
8. Change the Wisp URL with `chemical.setWisp`
|
|
180
210
|
|
|
181
211
|
```js
|
|
182
|
-
await
|
|
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,13 +223,21 @@ 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" &&
|
|
197
|
-
window.location = await
|
|
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>
|
|
201
231
|
```
|
|
202
232
|
|
|
233
|
+
9. Fetch websites through Wisp using `chemical.fetch`. This works the same as the fetch API.
|
|
234
|
+
|
|
235
|
+
10. Get search suggestions via DuckDuckGo using `chemical.getSuggestions`
|
|
236
|
+
|
|
237
|
+
```js
|
|
238
|
+
await chemical.getSuggestions("google")
|
|
239
|
+
```
|
|
240
|
+
|
|
203
241
|
## Vite Plugin
|
|
204
242
|
|
|
205
243
|
1. Create a new vite app and open `vite.config.js` or `vite.config.ts`
|
|
@@ -321,13 +359,5 @@ Set the second parameter of `chemicalAction` to the `id` of the iframe.
|
|
|
321
359
|
<iframe controls="my-controls-2" id="my-iframe-2" is="chemical-iframe"></iframe>
|
|
322
360
|
```
|
|
323
361
|
|
|
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
362
|
## License
|
|
333
363
|
Chemical uses the AGPL 3.0 license.
|
package/client/chemical.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
window.
|
|
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
|
|
181
|
+
async function encodeService(url, service) {
|
|
178
182
|
switch (service) {
|
|
179
183
|
case "uv":
|
|
180
184
|
if (uvEnabled) {
|
|
@@ -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
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
|
222
|
-
await connection.setTransport(getTransport(
|
|
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
|
-
|
|
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
|
|
4
|
+
const [app, listen] = new ChemicalServer();
|
|
5
5
|
const port = process.env.PORT || 3000;
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
app.use(express.static("public", {
|
|
8
8
|
index: "index.html",
|
|
9
9
|
extensions: ["html"]
|
|
10
10
|
}));
|
|
11
11
|
|
|
12
|
-
|
|
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
|
-
|
|
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.
|
|
12
|
+
"chemicaljs": "^1.7.0",
|
|
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.
|
|
413
|
-
"resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-tls/-/epoxy-tls-2.1.
|
|
414
|
-
"integrity": "sha512-
|
|
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.
|
|
418
|
-
"resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-transport/-/epoxy-transport-2.1.
|
|
419
|
-
"integrity": "sha512-
|
|
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.
|
|
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.
|
|
1167
|
-
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.
|
|
1168
|
-
"integrity": "sha512-
|
|
1166
|
+
"version": "1.7.0",
|
|
1167
|
+
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.7.0.tgz",
|
|
1168
|
+
"integrity": "sha512-iIbcitiDr9ouLaa6uyM+FnPXMKxmfopXHazIoDE401/b2OJBg3RhFEEMhpUxCdB5zXX9w5snVEeX5nekMlZO+A==",
|
|
1169
1169
|
"dependencies": {
|
|
1170
1170
|
"@mercuryworkshop/bare-mux": "^2.0.4",
|
|
1171
|
-
"@mercuryworkshop/epoxy-transport": "^2.1.
|
|
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",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"version": "1.0.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"chemicaljs": "^1.
|
|
12
|
+
"chemicaljs": "^1.7.0",
|
|
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.
|
|
413
|
-
"resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-tls/-/epoxy-tls-2.1.
|
|
414
|
-
"integrity": "sha512-
|
|
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.
|
|
418
|
-
"resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-transport/-/epoxy-transport-2.1.
|
|
419
|
-
"integrity": "sha512-
|
|
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.
|
|
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.
|
|
1167
|
-
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.
|
|
1168
|
-
"integrity": "sha512-
|
|
1166
|
+
"version": "1.7.0",
|
|
1167
|
+
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.7.0.tgz",
|
|
1168
|
+
"integrity": "sha512-iIbcitiDr9ouLaa6uyM+FnPXMKxmfopXHazIoDE401/b2OJBg3RhFEEMhpUxCdB5zXX9w5snVEeX5nekMlZO+A==",
|
|
1169
1169
|
"dependencies": {
|
|
1170
1170
|
"@mercuryworkshop/bare-mux": "^2.0.4",
|
|
1171
|
-
"@mercuryworkshop/epoxy-transport": "^2.1.
|
|
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",
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { ChemicalServer } from "chemicaljs";
|
|
2
2
|
import express from "express";
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const [app, listen] = new ChemicalServer();
|
|
5
5
|
const port = process.env.PORT || 3000;
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
app.use(express.static("public", {
|
|
8
8
|
index: "index.html",
|
|
9
9
|
extensions: ["html"]
|
|
10
10
|
}));
|
|
11
11
|
|
|
12
|
-
|
|
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.
|
|
12
|
+
"chemicaljs": "^1.7.0",
|
|
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.
|
|
413
|
-
"resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-tls/-/epoxy-tls-2.1.
|
|
414
|
-
"integrity": "sha512-
|
|
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.
|
|
418
|
-
"resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-transport/-/epoxy-transport-2.1.
|
|
419
|
-
"integrity": "sha512-
|
|
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.
|
|
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.
|
|
1167
|
-
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.
|
|
1168
|
-
"integrity": "sha512-
|
|
1166
|
+
"version": "1.7.0",
|
|
1167
|
+
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.7.0.tgz",
|
|
1168
|
+
"integrity": "sha512-iIbcitiDr9ouLaa6uyM+FnPXMKxmfopXHazIoDE401/b2OJBg3RhFEEMhpUxCdB5zXX9w5snVEeX5nekMlZO+A==",
|
|
1169
1169
|
"dependencies": {
|
|
1170
1170
|
"@mercuryworkshop/bare-mux": "^2.0.4",
|
|
1171
|
-
"@mercuryworkshop/epoxy-transport": "^2.1.
|
|
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",
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { ChemicalServer } from "chemicaljs";
|
|
2
2
|
import express from "express";
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const [app, listen] = new ChemicalServer();
|
|
5
5
|
const port = process.env.PORT || 3000;
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
app.use(express.static("public", {
|
|
8
8
|
index: "index.html",
|
|
9
9
|
extensions: ["html"]
|
|
10
10
|
}));
|
|
11
11
|
|
|
12
|
-
|
|
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.
|
|
12
|
+
"chemicaljs": "^1.7.0",
|
|
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.
|
|
413
|
-
"resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-tls/-/epoxy-tls-2.1.
|
|
414
|
-
"integrity": "sha512-
|
|
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.
|
|
418
|
-
"resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-transport/-/epoxy-transport-2.1.
|
|
419
|
-
"integrity": "sha512-
|
|
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.
|
|
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.
|
|
1167
|
-
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.
|
|
1168
|
-
"integrity": "sha512-
|
|
1166
|
+
"version": "1.7.0",
|
|
1167
|
+
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.7.0.tgz",
|
|
1168
|
+
"integrity": "sha512-iIbcitiDr9ouLaa6uyM+FnPXMKxmfopXHazIoDE401/b2OJBg3RhFEEMhpUxCdB5zXX9w5snVEeX5nekMlZO+A==",
|
|
1169
1169
|
"dependencies": {
|
|
1170
1170
|
"@mercuryworkshop/bare-mux": "^2.0.4",
|
|
1171
|
-
"@mercuryworkshop/epoxy-transport": "^2.1.
|
|
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",
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { ChemicalServer } from "chemicaljs";
|
|
2
2
|
import express from "express";
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const [app, listen] = new ChemicalServer();
|
|
5
5
|
const port = process.env.PORT || 3000;
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
app.use(express.static("dist", {
|
|
8
8
|
index: "index.html",
|
|
9
9
|
extensions: ["html"]
|
|
10
10
|
}));
|
|
11
11
|
|
|
12
|
-
|
|
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.
|
|
9
|
+
"chemicaljs": "^1.7.0",
|
|
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.
|
|
800
|
-
"resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-tls/-/epoxy-tls-2.1.
|
|
801
|
-
"integrity": "sha512-
|
|
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.
|
|
805
|
-
"resolved": "https://registry.npmjs.org/@mercuryworkshop/epoxy-transport/-/epoxy-transport-2.1.
|
|
806
|
-
"integrity": "sha512-
|
|
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.
|
|
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.
|
|
1730
|
-
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.
|
|
1731
|
-
"integrity": "sha512-
|
|
1729
|
+
"version": "1.7.0",
|
|
1730
|
+
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.7.0.tgz",
|
|
1731
|
+
"integrity": "sha512-iIbcitiDr9ouLaa6uyM+FnPXMKxmfopXHazIoDE401/b2OJBg3RhFEEMhpUxCdB5zXX9w5snVEeX5nekMlZO+A==",
|
|
1732
1732
|
"dependencies": {
|
|
1733
1733
|
"@mercuryworkshop/bare-mux": "^2.0.4",
|
|
1734
|
-
"@mercuryworkshop/epoxy-transport": "^2.1.
|
|
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",
|
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.
|
|
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
|
-
|
|
165
|
-
|
|
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
|
|