chemicaljs 1.6.2 → 1.6.4

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
@@ -43,14 +43,24 @@ 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.app.get("/", function(req, res){
49
+ chemical.get("/", function(req, res){
50
50
  res.send("Hello World");
51
51
  });
52
52
  ```
53
53
 
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.
56
+
57
+ ```js
58
+ chemical.error((req, res) => {
59
+ res.status(404);
60
+ res.send("404 Error");
61
+ });
62
+ ```
63
+
54
64
  4. Use `chemical.listen` on a port of your choosing.
55
65
 
56
66
  ```js
@@ -59,6 +69,7 @@ chemical.listen(3000);
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,11 +77,16 @@ import express from "express";
66
77
  const chemical = new ChemicalServer();
67
78
  const port = process.env.PORT || 3000;
68
79
 
69
- chemical.app.use(express.static("public", {
80
+ chemical.use(express.static("public", {
70
81
  index: "index.html",
71
82
  extensions: ["html"]
72
83
  }));
73
84
 
85
+ chemical.error((req, res) => {
86
+ res.status(404);
87
+ res.send("404 Error");
88
+ });
89
+
74
90
  chemical.listen(port, () => {
75
91
  console.log(`Chemical demo listening on port ${port}`);
76
92
  });
@@ -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.app.use(express.static("public", {
7
+ chemical.use(express.static("public", {
8
8
  index: "index.html",
9
9
  extensions: ["html"]
10
10
  }));
11
11
 
12
+ chemical.error((req, res) => {
13
+ res.status(404);
14
+ res.send("404 Error");
15
+ });
16
+
12
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.1",
12
+ "chemicaljs": "^1.6.3",
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.1",
1171
- "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.1.tgz",
1172
- "integrity": "sha512-iolcUgXd4eHC9vB6/7CMXIOpRNEEErO5SMPCv54h0wgPdnoOP/pfZqseYgDfyMl398zKDCWSC5x8GPhLaqNK4g==",
1170
+ "version": "1.6.3",
1171
+ "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.3.tgz",
1172
+ "integrity": "sha512-6s4b6++FmIHBITQ+FO3MCvrPmisKNf49EaByUjmIzCyLnYle2NL/aPwYgg3BaURQwAkBohyqjhi3Sqqx17ZJeg==",
1173
1173
  "dependencies": {
1174
1174
  "@mercuryworkshop/bare-mux": "^2.0.4",
1175
1175
  "@mercuryworkshop/epoxy-transport": "^2.1.3",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "homepage": "https://github.com/chemicaljs/chemical#readme",
20
20
  "dependencies": {
21
- "chemicaljs": "^1.6.1",
21
+ "chemicaljs": "^1.6.3",
22
22
  "express": "^4.19.2"
23
23
  }
24
24
  }
@@ -6,7 +6,7 @@ const chemical = new ChemicalServer({
6
6
  });
7
7
  const port = process.env.PORT || 3000;
8
8
 
9
- chemical.app.use(express.static("public", {
9
+ chemical.use(express.static("public", {
10
10
  index: "index.html",
11
11
  extensions: ["html"]
12
12
  }));
@@ -9,7 +9,7 @@
9
9
  "version": "1.0.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
- "chemicaljs": "^1.6.1",
12
+ "chemicaljs": "^1.6.3",
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.1",
1171
- "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.1.tgz",
1172
- "integrity": "sha512-iolcUgXd4eHC9vB6/7CMXIOpRNEEErO5SMPCv54h0wgPdnoOP/pfZqseYgDfyMl398zKDCWSC5x8GPhLaqNK4g==",
1170
+ "version": "1.6.3",
1171
+ "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.3.tgz",
1172
+ "integrity": "sha512-6s4b6++FmIHBITQ+FO3MCvrPmisKNf49EaByUjmIzCyLnYle2NL/aPwYgg3BaURQwAkBohyqjhi3Sqqx17ZJeg==",
1173
1173
  "dependencies": {
1174
1174
  "@mercuryworkshop/bare-mux": "^2.0.4",
1175
1175
  "@mercuryworkshop/epoxy-transport": "^2.1.3",
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "homepage": "https://github.com/chemicaljs/chemical#readme",
21
21
  "dependencies": {
22
- "chemicaljs": "^1.6.1",
22
+ "chemicaljs": "^1.6.3",
23
23
  "express": "^4.19.2"
24
24
  }
25
25
  }
@@ -4,7 +4,7 @@ import express from "express";
4
4
  const chemical = new ChemicalServer();
5
5
  const port = process.env.PORT || 3000;
6
6
 
7
- chemical.app.use(express.static("public", {
7
+ chemical.use(express.static("public", {
8
8
  index: "index.html",
9
9
  extensions: ["html"]
10
10
  }));
@@ -9,7 +9,7 @@
9
9
  "version": "1.0.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
- "chemicaljs": "^1.6.1",
12
+ "chemicaljs": "^1.6.3",
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.1",
1171
- "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.1.tgz",
1172
- "integrity": "sha512-iolcUgXd4eHC9vB6/7CMXIOpRNEEErO5SMPCv54h0wgPdnoOP/pfZqseYgDfyMl398zKDCWSC5x8GPhLaqNK4g==",
1170
+ "version": "1.6.3",
1171
+ "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.3.tgz",
1172
+ "integrity": "sha512-6s4b6++FmIHBITQ+FO3MCvrPmisKNf49EaByUjmIzCyLnYle2NL/aPwYgg3BaURQwAkBohyqjhi3Sqqx17ZJeg==",
1173
1173
  "dependencies": {
1174
1174
  "@mercuryworkshop/bare-mux": "^2.0.4",
1175
1175
  "@mercuryworkshop/epoxy-transport": "^2.1.3",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "homepage": "https://github.com/chemicaljs/chemical#readme",
20
20
  "dependencies": {
21
- "chemicaljs": "^1.6.1",
21
+ "chemicaljs": "^1.6.3",
22
22
  "express": "^4.19.2"
23
23
  }
24
24
  }
@@ -4,7 +4,7 @@ import express from "express";
4
4
  const chemical = new ChemicalServer();
5
5
  const port = process.env.PORT || 3000;
6
6
 
7
- chemical.app.use(express.static("public", {
7
+ chemical.use(express.static("public", {
8
8
  index: "index.html",
9
9
  extensions: ["html"]
10
10
  }));
@@ -9,7 +9,7 @@
9
9
  "version": "1.0.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
- "chemicaljs": "^1.6.1",
12
+ "chemicaljs": "^1.6.3",
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.1",
1171
- "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.1.tgz",
1172
- "integrity": "sha512-iolcUgXd4eHC9vB6/7CMXIOpRNEEErO5SMPCv54h0wgPdnoOP/pfZqseYgDfyMl398zKDCWSC5x8GPhLaqNK4g==",
1170
+ "version": "1.6.3",
1171
+ "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.3.tgz",
1172
+ "integrity": "sha512-6s4b6++FmIHBITQ+FO3MCvrPmisKNf49EaByUjmIzCyLnYle2NL/aPwYgg3BaURQwAkBohyqjhi3Sqqx17ZJeg==",
1173
1173
  "dependencies": {
1174
1174
  "@mercuryworkshop/bare-mux": "^2.0.4",
1175
1175
  "@mercuryworkshop/epoxy-transport": "^2.1.3",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "homepage": "https://github.com/chemicaljs/chemical#readme",
20
20
  "dependencies": {
21
- "chemicaljs": "^1.6.1",
21
+ "chemicaljs": "^1.6.3",
22
22
  "express": "^4.19.2"
23
23
  }
24
24
  }
@@ -4,7 +4,7 @@ import express from "express";
4
4
  const chemical = new ChemicalServer();
5
5
  const port = process.env.PORT || 3000;
6
6
 
7
- chemical.app.use(express.static("dist", {
7
+ chemical.use(express.static("dist", {
8
8
  index: "index.html",
9
9
  extensions: ["html"]
10
10
  }));
@@ -6,7 +6,7 @@
6
6
  "": {
7
7
  "name": "chemical-example-vite",
8
8
  "dependencies": {
9
- "chemicaljs": "^1.6.1",
9
+ "chemicaljs": "^1.6.3",
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.1",
1734
- "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.1.tgz",
1735
- "integrity": "sha512-iolcUgXd4eHC9vB6/7CMXIOpRNEEErO5SMPCv54h0wgPdnoOP/pfZqseYgDfyMl398zKDCWSC5x8GPhLaqNK4g==",
1733
+ "version": "1.6.3",
1734
+ "resolved": "https://registry.npmjs.org/chemicaljs/-/chemicaljs-1.6.3.tgz",
1735
+ "integrity": "sha512-6s4b6++FmIHBITQ+FO3MCvrPmisKNf49EaByUjmIzCyLnYle2NL/aPwYgg3BaURQwAkBohyqjhi3Sqqx17ZJeg==",
1736
1736
  "dependencies": {
1737
1737
  "@mercuryworkshop/bare-mux": "^2.0.4",
1738
1738
  "@mercuryworkshop/epoxy-transport": "^2.1.3",
@@ -8,7 +8,7 @@
8
8
  "build": "vite build"
9
9
  },
10
10
  "dependencies": {
11
- "chemicaljs": "^1.6.1",
11
+ "chemicaljs": "^1.6.3",
12
12
  "express": "^4.19.2",
13
13
  "preact": "^10.23.1"
14
14
  },
package/index.js CHANGED
@@ -41,6 +41,18 @@ class ChemicalServer {
41
41
  this.options = options;
42
42
 
43
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
+ }
44
56
  }
45
57
  listen(port, callback) {
46
58
  const server = createServer();
@@ -148,6 +160,14 @@ class ChemicalServer {
148
160
  }
149
161
  });
150
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
+
151
171
  server.listen(port, callback)
152
172
  }
153
173
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chemicaljs",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "description": "Easily create your own web proxy with no experience required.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,11 +12,11 @@
12
12
  "license": "AGPL-3.0-only",
13
13
  "dependencies": {
14
14
  "@mercuryworkshop/bare-mux": "^2.0.4",
15
- "@mercuryworkshop/epoxy-transport": "^2.1.3",
15
+ "@mercuryworkshop/epoxy-transport": "^2.1.5",
16
16
  "@mercuryworkshop/libcurl-transport": "^1.3.7",
17
17
  "@mercuryworkshop/scramjet": "^1.0.2",
18
18
  "@mercuryworkshop/wisp-js": "^0.1.1",
19
- "@titaniumnetwork-dev/ultraviolet": "^3.2.6",
19
+ "@titaniumnetwork-dev/ultraviolet": "^3.2.7",
20
20
  "express": "^4.19.2",
21
21
  "rammerhead": "https://github.com/chemicaljs/chemical/raw/main/rammerhead.tgz"
22
22
  }