chemicaljs 1.6.1 → 1.6.3
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 +22 -6
- package/examples/example/index.js +7 -2
- package/examples/example/package-lock.json +4 -4
- package/examples/example/package.json +1 -1
- package/examples/example-build/index.js +2 -2
- package/examples/example-build/package-lock.json +4 -4
- package/examples/example-build/package.json +1 -1
- package/examples/example-components/index.js +2 -2
- package/examples/example-components/package-lock.json +4 -4
- package/examples/example-components/package.json +1 -1
- package/examples/example-styled/index.js +2 -2
- package/examples/example-styled/package-lock.json +4 -4
- package/examples/example-styled/package.json +1 -1
- package/examples/example-vite/index.js +2 -2
- package/examples/example-vite/package-lock.json +4 -4
- package/examples/example-vite/package.json +1 -1
- package/index.js +50 -23
- package/package.json +1 -1
- package/update.bash +3 -0
- package/dist/baremux/baretypes.d.ts +0 -22
- package/dist/baremux/client.d.ts +0 -73
- package/dist/baremux/connection.d.ts +0 -43
- package/dist/baremux/index.d.ts +0 -9
- package/dist/baremux/index.js +0 -542
- package/dist/baremux/index.js.map +0 -1
- package/dist/baremux/index.mjs +0 -525
- package/dist/baremux/index.mjs.map +0 -1
- package/dist/baremux/snapshot.d.ts +0 -44
- package/dist/baremux/worker.d.ts +0 -1
- package/dist/baremux/worker.js +0 -166
- package/dist/baremux/worker.js.map +0 -1
- package/dist/baremux/workerHandlers.d.ts +0 -5
- package/dist/chemical.js +0 -268
- package/dist/chemical.sw.js +0 -38
- package/dist/epoxy/index.js +0 -1615
- package/dist/epoxy/index.mjs +0 -1562
- package/dist/libcurl/index.cjs +0 -6634
- package/dist/libcurl/index.js +0 -6634
- package/dist/libcurl/index.mjs +0 -6589
- package/dist/scramjet/scramjet.bundle.js +0 -7
- package/dist/scramjet/scramjet.bundle.js.map +0 -7
- package/dist/scramjet/scramjet.client.js +0 -1
- package/dist/scramjet/scramjet.client.js.map +0 -7
- package/dist/scramjet/scramjet.codecs.js +0 -3
- package/dist/scramjet/scramjet.codecs.js.map +0 -7
- package/dist/scramjet/scramjet.config.js +0 -9
- package/dist/scramjet/scramjet.config.js.map +0 -7
- package/dist/scramjet/scramjet.worker.js +0 -42
- package/dist/scramjet/scramjet.worker.js.map +0 -7
- package/dist/uv/sw.js +0 -24
- package/dist/uv/uv.bundle.js +0 -8
- package/dist/uv/uv.bundle.js.map +0 -7
- package/dist/uv/uv.client.js +0 -5
- package/dist/uv/uv.client.js.map +0 -7
- package/dist/uv/uv.config.js +0 -10
- package/dist/uv/uv.handler.js +0 -2
- package/dist/uv/uv.handler.js.map +0 -7
- package/dist/uv/uv.sw.js +0 -45
- package/dist/uv/uv.sw.js.map +0 -7
package/README.md
CHANGED
|
@@ -43,22 +43,33 @@ const chemical = new ChemicalServer({
|
|
|
43
43
|
|
|
44
44
|
`hostname_whitelist` overrides `hostname_blacklist` if you try to set them both.
|
|
45
45
|
|
|
46
|
-
3. Use `chemical.app` which is an express app. You may need to import express for certain APIs.
|
|
46
|
+
3. Use `chemical.app` which is an express app. `chemical.use` is shortand for `chemical.app.use`. You may need to import express for certain APIs.
|
|
47
47
|
|
|
48
48
|
```js
|
|
49
|
-
chemical.
|
|
49
|
+
chemical.get("/", function(req, res){
|
|
50
50
|
res.send("Hello World");
|
|
51
51
|
});
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
|
|
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.
|
|
55
56
|
|
|
56
57
|
```js
|
|
57
|
-
chemical.
|
|
58
|
+
chemical.error((req, res) => {
|
|
59
|
+
res.status(404);
|
|
60
|
+
res.send("404 Error");
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
4. Use `chemical.listen` on a port of your choosing.
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
chemical.listen(3000);
|
|
58
68
|
```
|
|
59
69
|
|
|
60
70
|
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.
|
|
61
71
|
|
|
72
|
+
|
|
62
73
|
```js
|
|
63
74
|
import { ChemicalServer } from "chemicaljs";
|
|
64
75
|
import express from "express";
|
|
@@ -66,12 +77,17 @@ import express from "express";
|
|
|
66
77
|
const chemical = new ChemicalServer();
|
|
67
78
|
const port = process.env.PORT || 3000;
|
|
68
79
|
|
|
69
|
-
chemical.
|
|
80
|
+
chemical.use(express.static("public", {
|
|
70
81
|
index: "index.html",
|
|
71
82
|
extensions: ["html"]
|
|
72
83
|
}));
|
|
73
84
|
|
|
74
|
-
chemical.
|
|
85
|
+
chemical.error((req, res) => {
|
|
86
|
+
res.status(404);
|
|
87
|
+
res.send("404 Error");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
chemical.listen(port, () => {
|
|
75
91
|
console.log(`Chemical demo listening on port ${port}`);
|
|
76
92
|
});
|
|
77
93
|
```
|
|
@@ -4,11 +4,16 @@ import express from "express";
|
|
|
4
4
|
const chemical = new ChemicalServer();
|
|
5
5
|
const port = process.env.PORT || 3000;
|
|
6
6
|
|
|
7
|
-
chemical.
|
|
7
|
+
chemical.use(express.static("public", {
|
|
8
8
|
index: "index.html",
|
|
9
9
|
extensions: ["html"]
|
|
10
10
|
}));
|
|
11
11
|
|
|
12
|
-
chemical.
|
|
12
|
+
chemical.error((req, res) => {
|
|
13
|
+
res.status(404);
|
|
14
|
+
res.send("404 Error");
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
chemical.listen(port, () => {
|
|
13
18
|
console.log(`Chemical example listening on port ${port}`);
|
|
14
19
|
});
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"version": "1.0.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"chemicaljs": "^1.6.
|
|
12
|
+
"chemicaljs": "^1.6.2",
|
|
13
13
|
"express": "^4.19.2"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
@@ -1167,9 +1167,9 @@
|
|
|
1167
1167
|
}
|
|
1168
1168
|
},
|
|
1169
1169
|
"node_modules/chemicaljs": {
|
|
1170
|
-
"version": "1.6.
|
|
1171
|
-
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.
|
|
1172
|
-
"integrity": "sha512-
|
|
1170
|
+
"version": "1.6.2",
|
|
1171
|
+
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.2.tgz",
|
|
1172
|
+
"integrity": "sha512-p6WMjI3VHAGUBvJNNh9YJrvNTxcL2iS2y4mbVlMC66yvNzGx97O+ZAm8P9wwKJQFUpoQjFaW9retd/qTDIDNTg==",
|
|
1173
1173
|
"dependencies": {
|
|
1174
1174
|
"@mercuryworkshop/bare-mux": "^2.0.4",
|
|
1175
1175
|
"@mercuryworkshop/epoxy-transport": "^2.1.3",
|
|
@@ -6,11 +6,11 @@ const chemical = new ChemicalServer({
|
|
|
6
6
|
});
|
|
7
7
|
const port = process.env.PORT || 3000;
|
|
8
8
|
|
|
9
|
-
chemical.
|
|
9
|
+
chemical.use(express.static("public", {
|
|
10
10
|
index: "index.html",
|
|
11
11
|
extensions: ["html"]
|
|
12
12
|
}));
|
|
13
13
|
|
|
14
|
-
chemical.
|
|
14
|
+
chemical.listen(port, () => {
|
|
15
15
|
console.log(`Chemical example build listening on port ${port}`);
|
|
16
16
|
});
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"version": "1.0.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"chemicaljs": "^1.6.
|
|
12
|
+
"chemicaljs": "^1.6.2",
|
|
13
13
|
"express": "^4.19.2"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
@@ -1167,9 +1167,9 @@
|
|
|
1167
1167
|
}
|
|
1168
1168
|
},
|
|
1169
1169
|
"node_modules/chemicaljs": {
|
|
1170
|
-
"version": "1.6.
|
|
1171
|
-
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.
|
|
1172
|
-
"integrity": "sha512-
|
|
1170
|
+
"version": "1.6.2",
|
|
1171
|
+
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.2.tgz",
|
|
1172
|
+
"integrity": "sha512-p6WMjI3VHAGUBvJNNh9YJrvNTxcL2iS2y4mbVlMC66yvNzGx97O+ZAm8P9wwKJQFUpoQjFaW9retd/qTDIDNTg==",
|
|
1173
1173
|
"dependencies": {
|
|
1174
1174
|
"@mercuryworkshop/bare-mux": "^2.0.4",
|
|
1175
1175
|
"@mercuryworkshop/epoxy-transport": "^2.1.3",
|
|
@@ -4,11 +4,11 @@ import express from "express";
|
|
|
4
4
|
const chemical = new ChemicalServer();
|
|
5
5
|
const port = process.env.PORT || 3000;
|
|
6
6
|
|
|
7
|
-
chemical.
|
|
7
|
+
chemical.use(express.static("public", {
|
|
8
8
|
index: "index.html",
|
|
9
9
|
extensions: ["html"]
|
|
10
10
|
}));
|
|
11
11
|
|
|
12
|
-
chemical.
|
|
12
|
+
chemical.listen(port, () => {
|
|
13
13
|
console.log(`Chemical example components listening on port ${port}`);
|
|
14
14
|
});
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"version": "1.0.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"chemicaljs": "^1.6.
|
|
12
|
+
"chemicaljs": "^1.6.2",
|
|
13
13
|
"express": "^4.19.2"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
@@ -1167,9 +1167,9 @@
|
|
|
1167
1167
|
}
|
|
1168
1168
|
},
|
|
1169
1169
|
"node_modules/chemicaljs": {
|
|
1170
|
-
"version": "1.6.
|
|
1171
|
-
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.
|
|
1172
|
-
"integrity": "sha512-
|
|
1170
|
+
"version": "1.6.2",
|
|
1171
|
+
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.2.tgz",
|
|
1172
|
+
"integrity": "sha512-p6WMjI3VHAGUBvJNNh9YJrvNTxcL2iS2y4mbVlMC66yvNzGx97O+ZAm8P9wwKJQFUpoQjFaW9retd/qTDIDNTg==",
|
|
1173
1173
|
"dependencies": {
|
|
1174
1174
|
"@mercuryworkshop/bare-mux": "^2.0.4",
|
|
1175
1175
|
"@mercuryworkshop/epoxy-transport": "^2.1.3",
|
|
@@ -4,11 +4,11 @@ import express from "express";
|
|
|
4
4
|
const chemical = new ChemicalServer();
|
|
5
5
|
const port = process.env.PORT || 3000;
|
|
6
6
|
|
|
7
|
-
chemical.
|
|
7
|
+
chemical.use(express.static("public", {
|
|
8
8
|
index: "index.html",
|
|
9
9
|
extensions: ["html"]
|
|
10
10
|
}));
|
|
11
11
|
|
|
12
|
-
chemical.
|
|
12
|
+
chemical.listen(port, () => {
|
|
13
13
|
console.log(`Chemical example styled listening on port ${port}`);
|
|
14
14
|
});
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"version": "1.0.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"chemicaljs": "^1.6.
|
|
12
|
+
"chemicaljs": "^1.6.2",
|
|
13
13
|
"express": "^4.19.2"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
@@ -1167,9 +1167,9 @@
|
|
|
1167
1167
|
}
|
|
1168
1168
|
},
|
|
1169
1169
|
"node_modules/chemicaljs": {
|
|
1170
|
-
"version": "1.6.
|
|
1171
|
-
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.
|
|
1172
|
-
"integrity": "sha512-
|
|
1170
|
+
"version": "1.6.2",
|
|
1171
|
+
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.2.tgz",
|
|
1172
|
+
"integrity": "sha512-p6WMjI3VHAGUBvJNNh9YJrvNTxcL2iS2y4mbVlMC66yvNzGx97O+ZAm8P9wwKJQFUpoQjFaW9retd/qTDIDNTg==",
|
|
1173
1173
|
"dependencies": {
|
|
1174
1174
|
"@mercuryworkshop/bare-mux": "^2.0.4",
|
|
1175
1175
|
"@mercuryworkshop/epoxy-transport": "^2.1.3",
|
|
@@ -4,11 +4,11 @@ import express from "express";
|
|
|
4
4
|
const chemical = new ChemicalServer();
|
|
5
5
|
const port = process.env.PORT || 3000;
|
|
6
6
|
|
|
7
|
-
chemical.
|
|
7
|
+
chemical.use(express.static("dist", {
|
|
8
8
|
index: "index.html",
|
|
9
9
|
extensions: ["html"]
|
|
10
10
|
}));
|
|
11
11
|
|
|
12
|
-
chemical.
|
|
12
|
+
chemical.listen(port, () => {
|
|
13
13
|
console.log(`Chemical example vite listening on port ${port}`);
|
|
14
14
|
});
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"": {
|
|
7
7
|
"name": "chemical-example-vite",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"chemicaljs": "^1.6.
|
|
9
|
+
"chemicaljs": "^1.6.2",
|
|
10
10
|
"express": "^4.19.2",
|
|
11
11
|
"preact": "^10.23.1"
|
|
12
12
|
},
|
|
@@ -1730,9 +1730,9 @@
|
|
|
1730
1730
|
}
|
|
1731
1731
|
},
|
|
1732
1732
|
"node_modules/chemicaljs": {
|
|
1733
|
-
"version": "1.6.
|
|
1734
|
-
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.
|
|
1735
|
-
"integrity": "sha512-
|
|
1733
|
+
"version": "1.6.2",
|
|
1734
|
+
"resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.2.tgz",
|
|
1735
|
+
"integrity": "sha512-p6WMjI3VHAGUBvJNNh9YJrvNTxcL2iS2y4mbVlMC66yvNzGx97O+ZAm8P9wwKJQFUpoQjFaW9retd/qTDIDNTg==",
|
|
1736
1736
|
"dependencies": {
|
|
1737
1737
|
"@mercuryworkshop/bare-mux": "^2.0.4",
|
|
1738
1738
|
"@mercuryworkshop/epoxy-transport": "^2.1.3",
|
package/index.js
CHANGED
|
@@ -38,6 +38,25 @@ class ChemicalServer {
|
|
|
38
38
|
options.rammerhead = true;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
this.options = options;
|
|
42
|
+
|
|
43
|
+
this.app = express();
|
|
44
|
+
this.use = this.app.use.bind(this.app);
|
|
45
|
+
this.errorFunctions = [];
|
|
46
|
+
|
|
47
|
+
this.error = (newErrorFunction) => {
|
|
48
|
+
if (newErrorFunction) {
|
|
49
|
+
if (typeof newErrorFunction == "function") {
|
|
50
|
+
this.errorFunctions.push(newErrorFunction);
|
|
51
|
+
} else {
|
|
52
|
+
console.error("Error: Invalid type for Chemical error function.")
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
listen(port, callback) {
|
|
58
|
+
const server = createServer();
|
|
59
|
+
|
|
41
60
|
const rh = createRammerhead()
|
|
42
61
|
|
|
43
62
|
const rammerheadScopes = [
|
|
@@ -75,14 +94,12 @@ class ChemicalServer {
|
|
|
75
94
|
rh.emit("upgrade", req, socket, head)
|
|
76
95
|
}
|
|
77
96
|
|
|
78
|
-
this.
|
|
79
|
-
this.app = express();
|
|
80
|
-
this.app.get("/chemical.js", async function (req, res) {
|
|
97
|
+
this.app.get("/chemical.js", async (req, res) => {
|
|
81
98
|
let chemicalMain = await readFileSync(resolve(__dirname, "client/chemical.js"), "utf8");
|
|
82
99
|
|
|
83
|
-
if (options.default) {
|
|
84
|
-
if (["uv", "rammerhead", "scramjet"].includes(options.default)) {
|
|
85
|
-
chemicalMain = `const defaultService = "${options.default}";\n\n` + chemicalMain
|
|
100
|
+
if (this.options.default) {
|
|
101
|
+
if (["uv", "rammerhead", "scramjet"].includes(this.options.default)) {
|
|
102
|
+
chemicalMain = `const defaultService = "${this.options.default}";\n\n` + chemicalMain
|
|
86
103
|
} else {
|
|
87
104
|
chemicalMain = `const defaultService = "uv";\n\n` + chemicalMain
|
|
88
105
|
console.error("Error: Chemical default option invalid.")
|
|
@@ -91,19 +108,19 @@ class ChemicalServer {
|
|
|
91
108
|
chemicalMain = `const defaultService = "uv";\n\n` + chemicalMain;
|
|
92
109
|
}
|
|
93
110
|
|
|
94
|
-
chemicalMain = "const uvEnabled = " + String(options.uv) + ";\n" + chemicalMain
|
|
95
|
-
chemicalMain = "const scramjetEnabled = " + String(options.scramjet) + ";\n" + chemicalMain
|
|
96
|
-
chemicalMain = "const rammerheadEnabled = " + String(options.rammerhead) + ";\n" + chemicalMain
|
|
111
|
+
chemicalMain = "const uvEnabled = " + String(this.options.uv) + ";\n" + chemicalMain
|
|
112
|
+
chemicalMain = "const scramjetEnabled = " + String(this.options.scramjet) + ";\n" + chemicalMain
|
|
113
|
+
chemicalMain = "const rammerheadEnabled = " + String(this.options.rammerhead) + ";\n" + chemicalMain
|
|
97
114
|
|
|
98
115
|
res.type("application/javascript");
|
|
99
116
|
return res.send(chemicalMain);
|
|
100
117
|
});
|
|
101
|
-
this.app.get("/chemical.sw.js", async
|
|
118
|
+
this.app.get("/chemical.sw.js", async (req, res) => {
|
|
102
119
|
let chemicalSW = await readFileSync(resolve(__dirname, "client/chemical.sw.js"), "utf8");
|
|
103
120
|
|
|
104
|
-
chemicalSW = "const uvEnabled = " + String(options.uv) + ";\n" + chemicalSW
|
|
105
|
-
chemicalSW = "const scramjetEnabled = " + String(options.scramjet) + ";\n" + chemicalSW
|
|
106
|
-
chemicalSW = "const rammerheadEnabled = " + String(options.rammerhead) + ";\n" + chemicalSW
|
|
121
|
+
chemicalSW = "const uvEnabled = " + String(this.options.uv) + ";\n" + chemicalSW
|
|
122
|
+
chemicalSW = "const scramjetEnabled = " + String(this.options.scramjet) + ";\n" + chemicalSW
|
|
123
|
+
chemicalSW = "const rammerheadEnabled = " + String(this.options.rammerhead) + ";\n" + chemicalSW
|
|
107
124
|
|
|
108
125
|
res.type("application/javascript");
|
|
109
126
|
return res.send(chemicalSW);
|
|
@@ -112,36 +129,46 @@ class ChemicalServer {
|
|
|
112
129
|
this.app.use("/baremux/", express.static(baremuxPath));
|
|
113
130
|
this.app.use("/libcurl/", express.static(libcurlPath));
|
|
114
131
|
this.app.use("/epoxy/", express.static(epoxyPath));
|
|
115
|
-
if (options.uv) {
|
|
132
|
+
if (this.options.uv) {
|
|
116
133
|
this.app.use("/uv/", express.static(resolve(__dirname, "config/uv")));
|
|
117
134
|
this.app.use("/uv/", express.static(uvPath));
|
|
118
135
|
}
|
|
119
|
-
if (options.scramjet) {
|
|
136
|
+
if (this.options.scramjet) {
|
|
120
137
|
this.app.use("/scramjet/", express.static(resolve(__dirname, "config/scramjet")));
|
|
121
138
|
this.app.use("/scramjet/", express.static(scramjetPath));
|
|
122
139
|
}
|
|
123
|
-
|
|
124
|
-
if (options.rammerhead && shouldRouteRh(req)) {
|
|
140
|
+
server.on("request", (req, res) => {
|
|
141
|
+
if (this.options.rammerhead && shouldRouteRh(req)) {
|
|
125
142
|
routeRhRequest(req, res);
|
|
126
143
|
} else {
|
|
127
144
|
this.app(req, res);
|
|
128
145
|
}
|
|
129
146
|
});
|
|
130
|
-
|
|
147
|
+
server.on("upgrade", (req, socket, head) => {
|
|
131
148
|
if (req.url && req.url.endsWith("/wisp/")) {
|
|
132
|
-
if (options.hostname_blacklist) {
|
|
133
|
-
wisp.options.hostname_blacklist = options.hostname_blacklist
|
|
149
|
+
if (this.options.hostname_blacklist) {
|
|
150
|
+
wisp.this.options.hostname_blacklist = this.options.hostname_blacklist
|
|
134
151
|
}
|
|
135
|
-
if (options.hostname_whitelist) {
|
|
136
|
-
wisp.options.hostname_whitelist = options.hostname_whitelist
|
|
152
|
+
if (this.options.hostname_whitelist) {
|
|
153
|
+
wisp.this.options.hostname_whitelist = this.options.hostname_whitelist
|
|
137
154
|
}
|
|
138
155
|
wisp.routeRequest(req, socket, head);
|
|
139
|
-
} else if (options.rammerhead && shouldRouteRh(req)) {
|
|
156
|
+
} else if (this.options.rammerhead && shouldRouteRh(req)) {
|
|
140
157
|
routeRhUpgrade(req, socket, head);
|
|
141
158
|
} else {
|
|
142
159
|
socket.end();
|
|
143
160
|
}
|
|
144
161
|
});
|
|
162
|
+
|
|
163
|
+
if (this.errorFunctions.length) {
|
|
164
|
+
this.app.use((req, res) => {
|
|
165
|
+
for (let errorFunction of this.errorFunctions) {
|
|
166
|
+
errorFunction(req, res);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
server.listen(port, callback)
|
|
145
172
|
}
|
|
146
173
|
}
|
|
147
174
|
|
package/package.json
CHANGED
package/update.bash
CHANGED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export type BareHeaders = Record<string, string | string[]>;
|
|
2
|
-
export type BareMeta = {};
|
|
3
|
-
export type TransferrableResponse = {
|
|
4
|
-
body: ReadableStream | ArrayBuffer | Blob | string;
|
|
5
|
-
headers: BareHeaders;
|
|
6
|
-
status: number;
|
|
7
|
-
statusText: string;
|
|
8
|
-
};
|
|
9
|
-
export interface BareTransport {
|
|
10
|
-
init: () => Promise<void>;
|
|
11
|
-
ready: boolean;
|
|
12
|
-
connect: (url: URL, origin: string, protocols: string[], requestHeaders: BareHeaders, onopen: (protocol: string) => void, onmessage: (data: Blob | ArrayBuffer | string) => void, onclose: (code: number, reason: string) => void, onerror: (error: string) => void) => [(data: Blob | ArrayBuffer | string) => void, (code: number, reason: string) => void];
|
|
13
|
-
request: (remote: URL, method: string, body: BodyInit | null, headers: BareHeaders, signal: AbortSignal | undefined) => Promise<TransferrableResponse>;
|
|
14
|
-
meta: () => BareMeta;
|
|
15
|
-
}
|
|
16
|
-
export interface BareWebSocketMeta {
|
|
17
|
-
protocol: string;
|
|
18
|
-
setCookies: string[];
|
|
19
|
-
}
|
|
20
|
-
export type BareHTTPProtocol = 'blob:' | 'http:' | 'https:' | string;
|
|
21
|
-
export type BareWSProtocol = 'ws:' | 'wss:' | string;
|
|
22
|
-
export declare const maxRedirects = 20;
|
package/dist/baremux/client.d.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { BareHeaders, BareTransport } from './baretypes';
|
|
2
|
-
import { WorkerConnection } from './connection';
|
|
3
|
-
export declare function validProtocol(protocol: string): boolean;
|
|
4
|
-
export type WebSocketImpl = {
|
|
5
|
-
new (...args: ConstructorParameters<typeof WebSocket>): WebSocket;
|
|
6
|
-
};
|
|
7
|
-
export declare namespace BareWebSocket {
|
|
8
|
-
type GetReadyStateCallback = () => number;
|
|
9
|
-
type GetSendErrorCallback = () => Error | undefined;
|
|
10
|
-
type GetProtocolCallback = () => string;
|
|
11
|
-
type HeadersType = BareHeaders | Headers | undefined;
|
|
12
|
-
type HeadersProvider = BareHeaders | (() => BareHeaders | Promise<BareHeaders>);
|
|
13
|
-
interface Options {
|
|
14
|
-
/**
|
|
15
|
-
* A provider of request headers to pass to the remote.
|
|
16
|
-
* Usually one of `User-Agent`, `Origin`, and `Cookie`
|
|
17
|
-
* Can be just the headers object or an synchronous/asynchronous function that returns the headers object
|
|
18
|
-
*/
|
|
19
|
-
headers?: BareWebSocket.HeadersProvider;
|
|
20
|
-
/**
|
|
21
|
-
* A hook executed by this function with helper arguments for hooking the readyState property. If a hook isn't provided, bare-client will hook the property on the instance. Hooking it on an instance basis is good for small projects, but ideally the class should be hooked by the user of bare-client.
|
|
22
|
-
*/
|
|
23
|
-
readyStateHook?: ((socket: WebSocket, getReadyState: BareWebSocket.GetReadyStateCallback) => void) | undefined;
|
|
24
|
-
/**
|
|
25
|
-
* A hook executed by this function with helper arguments for determining if the send function should throw an error. If a hook isn't provided, bare-client will hook the function on the instance.
|
|
26
|
-
*/
|
|
27
|
-
sendErrorHook?: ((socket: WebSocket, getSendError: BareWebSocket.GetSendErrorCallback) => void) | undefined;
|
|
28
|
-
/**
|
|
29
|
-
* A hook executed by this function with the URL. If a hook isn't provided, bare-client will hook the URL.
|
|
30
|
-
*/
|
|
31
|
-
urlHook?: ((socket: WebSocket, url: URL) => void) | undefined;
|
|
32
|
-
/**
|
|
33
|
-
* A hook executed by this function with a helper for getting the current fake protocol. If a hook isn't provided, bare-client will hook the protocol.
|
|
34
|
-
*/
|
|
35
|
-
protocolHook?: ((socket: WebSocket, getProtocol: BareWebSocket.GetProtocolCallback) => void) | undefined;
|
|
36
|
-
/**
|
|
37
|
-
* A callback executed by this function with an array of cookies. This is called once the metadata from the server is received.
|
|
38
|
-
*/
|
|
39
|
-
setCookiesCallback?: ((setCookies: string[]) => void) | undefined;
|
|
40
|
-
webSocketImpl?: WebSocket;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* A Response with additional properties.
|
|
45
|
-
*/
|
|
46
|
-
export interface BareResponse extends Response {
|
|
47
|
-
rawResponse: Response;
|
|
48
|
-
rawHeaders: BareHeaders;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* A BareResponse with additional properties.
|
|
52
|
-
*/
|
|
53
|
-
export interface BareResponseFetch extends BareResponse {
|
|
54
|
-
finalURL: string;
|
|
55
|
-
}
|
|
56
|
-
export declare class BareMuxConnection {
|
|
57
|
-
worker: WorkerConnection;
|
|
58
|
-
constructor(workerPath: string);
|
|
59
|
-
getTransport(): Promise<string>;
|
|
60
|
-
setTransport(path: string, options: any[], transferables?: Transferable[]): Promise<void>;
|
|
61
|
-
setManualTransport(functionBody: string, options: any[], transferables?: Transferable[]): Promise<void>;
|
|
62
|
-
setRemoteTransport(transport: BareTransport, name: string): Promise<void>;
|
|
63
|
-
getInnerPort(): MessagePort | Promise<MessagePort>;
|
|
64
|
-
}
|
|
65
|
-
export declare class BareClient {
|
|
66
|
-
worker: WorkerConnection;
|
|
67
|
-
/**
|
|
68
|
-
* Create a BareClient. Calls to fetch and connect will wait for an implementation to be ready.
|
|
69
|
-
*/
|
|
70
|
-
constructor(worker?: string | MessagePort);
|
|
71
|
-
createWebSocket(remote: string | URL, protocols?: string | string[] | undefined, webSocketImpl?: WebSocketImpl, requestHeaders?: BareHeaders, arrayBufferImpl?: ArrayBuffer): WebSocket;
|
|
72
|
-
fetch(url: string | URL, init?: RequestInit): Promise<BareResponseFetch>;
|
|
73
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { BareHeaders, TransferrableResponse } from "./baretypes";
|
|
2
|
-
export type WorkerMessage = {
|
|
3
|
-
type: "fetch" | "websocket" | "set" | "get" | "ping";
|
|
4
|
-
fetch?: {
|
|
5
|
-
remote: string;
|
|
6
|
-
method: string;
|
|
7
|
-
headers: BareHeaders;
|
|
8
|
-
body: ReadableStream | ArrayBuffer | undefined;
|
|
9
|
-
};
|
|
10
|
-
websocket?: {
|
|
11
|
-
url: string;
|
|
12
|
-
origin: string;
|
|
13
|
-
protocols: string[];
|
|
14
|
-
requestHeaders: BareHeaders;
|
|
15
|
-
channel: MessagePort;
|
|
16
|
-
};
|
|
17
|
-
client?: {
|
|
18
|
-
function: string;
|
|
19
|
-
args: any[];
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
export type WorkerRequest = {
|
|
23
|
-
message: WorkerMessage;
|
|
24
|
-
port: MessagePort;
|
|
25
|
-
};
|
|
26
|
-
export type WorkerResponse = {
|
|
27
|
-
type: "fetch" | "websocket" | "set" | "get" | "pong" | "error";
|
|
28
|
-
fetch?: TransferrableResponse;
|
|
29
|
-
name?: string;
|
|
30
|
-
error?: Error;
|
|
31
|
-
};
|
|
32
|
-
export type BroadcastMessage = {
|
|
33
|
-
type: "refreshPort";
|
|
34
|
-
};
|
|
35
|
-
export declare function browserSupportsTransferringStreams(): boolean;
|
|
36
|
-
export declare class WorkerConnection {
|
|
37
|
-
channel: BroadcastChannel;
|
|
38
|
-
port: MessagePort | Promise<MessagePort>;
|
|
39
|
-
workerPath: string;
|
|
40
|
-
constructor(worker?: string | MessagePort);
|
|
41
|
-
createChannel(workerPath?: string, inInit?: boolean): void;
|
|
42
|
-
sendMessage(message: WorkerMessage, transferable?: Transferable[]): Promise<WorkerResponse>;
|
|
43
|
-
}
|
package/dist/baremux/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './baretypes';
|
|
2
|
-
export * from './client';
|
|
3
|
-
export * from './connection';
|
|
4
|
-
export { BareClient as default } from './client';
|
|
5
|
-
export { WebSocketFields } from "./snapshot";
|
|
6
|
-
export type * from './baretypes';
|
|
7
|
-
export type * from './client';
|
|
8
|
-
export type * from './connection';
|
|
9
|
-
export type * from "./snapshot";
|