chemicaljs 1.2.0 → 1.2.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/index.js +28 -36
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -11,9 +11,25 @@ import createRammerhead from "rammerhead/src/server/index.js";
|
|
|
11
11
|
|
|
12
12
|
class ChemicalServer {
|
|
13
13
|
constructor(options) {
|
|
14
|
-
if (
|
|
14
|
+
if (options) {
|
|
15
|
+
if (typeof options !== "object" || Array.isArray(options)) {
|
|
16
|
+
options = {}
|
|
17
|
+
console.error("Error: ChemicalServer options invalid.")
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
15
20
|
options = {}
|
|
16
|
-
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (!options.uv) {
|
|
24
|
+
options.uv = true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!options.scramjet) {
|
|
28
|
+
options.scramjet = true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!options.rammerhead) {
|
|
32
|
+
options.rammerhead = true;
|
|
17
33
|
}
|
|
18
34
|
|
|
19
35
|
const rh = createRammerhead()
|
|
@@ -67,21 +83,9 @@ class ChemicalServer {
|
|
|
67
83
|
}
|
|
68
84
|
}
|
|
69
85
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
chemicalMain = "const uvEnabled = true;\n" + chemicalMain
|
|
74
|
-
}
|
|
75
|
-
if (options.scramjet == false) {
|
|
76
|
-
chemicalMain = "const scramjetEnabled = false;\n" + chemicalMain
|
|
77
|
-
} else {
|
|
78
|
-
chemicalMain = "const scramjetEnabled = true;\n" + chemicalMain
|
|
79
|
-
}
|
|
80
|
-
if (options.rammerhead == false) {
|
|
81
|
-
chemicalMain = "const rammerheadEnabled = false;\n" + chemicalMain
|
|
82
|
-
} else {
|
|
83
|
-
chemicalMain = "const rammerheadEnabled = true;\n" + chemicalMain
|
|
84
|
-
}
|
|
86
|
+
chemicalMain = "const uvEnabled = " + String(options.uv) + ";\n" + chemicalMain
|
|
87
|
+
chemicalMain = "const scramjetEnabled = " + String(options.scramjet) + ";\n" + chemicalMain
|
|
88
|
+
chemicalMain = "const rammerheadEnabled = " + String(options.rammerhead) + ";\n" + chemicalMain
|
|
85
89
|
|
|
86
90
|
res.type("application/javascript");
|
|
87
91
|
return res.send(chemicalMain);
|
|
@@ -89,21 +93,9 @@ class ChemicalServer {
|
|
|
89
93
|
this.app.get("/chemical.sw.js", async function (req, res) {
|
|
90
94
|
let chemicalSW = await readFileSync(resolve(import.meta.dirname, "client/chemical.sw.js"), "utf8");
|
|
91
95
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
chemicalSW = "const uvEnabled = true;\n\n" + chemicalSW
|
|
96
|
-
}
|
|
97
|
-
if (options.scramjet == false) {
|
|
98
|
-
chemicalSW = "const scramjetEnabled = false;\n" + chemicalSW
|
|
99
|
-
} else {
|
|
100
|
-
chemicalSW = "const scramjetEnabled = true;\n" + chemicalSW
|
|
101
|
-
}
|
|
102
|
-
if (options.rammerhead == false) {
|
|
103
|
-
chemicalSW = "const rammerheadEnabled = false;\n" + chemicalSW
|
|
104
|
-
} else {
|
|
105
|
-
chemicalSW = "const rammerheadEnabled = true;\n" + chemicalSW
|
|
106
|
-
}
|
|
96
|
+
chemicalSW = "const uvEnabled = " + String(options.uv) + ";\n" + chemicalSW
|
|
97
|
+
chemicalSW = "const scramjetEnabled = " + String(options.scramjet) + ";\n" + chemicalSW
|
|
98
|
+
chemicalSW = "const rammerheadEnabled = " + String(options.rammerhead) + ";\n" + chemicalSW
|
|
107
99
|
|
|
108
100
|
res.type("application/javascript");
|
|
109
101
|
return res.send(chemicalSW);
|
|
@@ -111,16 +103,16 @@ class ChemicalServer {
|
|
|
111
103
|
this.app.use(express.static(resolve(import.meta.dirname, "client")));
|
|
112
104
|
this.app.use("/baremux/", express.static(baremuxPath));
|
|
113
105
|
this.app.use("/epoxy/", express.static(epoxyPath));
|
|
114
|
-
if (options.uv
|
|
106
|
+
if (options.uv) {
|
|
115
107
|
this.app.use("/uv/", express.static(resolve(import.meta.dirname, "config/uv")));
|
|
116
108
|
this.app.use("/uv/", express.static(uvPath));
|
|
117
109
|
}
|
|
118
|
-
if (options.scramjet
|
|
110
|
+
if (options.scramjet) {
|
|
119
111
|
this.app.use("/scramjet/", express.static(resolve(import.meta.dirname, "config/scramjet")));
|
|
120
112
|
this.app.use("/scramjet/", express.static(scramjetPath));
|
|
121
113
|
}
|
|
122
114
|
this.server.on("request", (req, res) => {
|
|
123
|
-
if (options.rammerhead
|
|
115
|
+
if (options.rammerhead && shouldRouteRh(req)) {
|
|
124
116
|
routeRhRequest(req, res);
|
|
125
117
|
} else {
|
|
126
118
|
this.app(req, res);
|
|
@@ -129,7 +121,7 @@ class ChemicalServer {
|
|
|
129
121
|
this.server.on("upgrade", (req, socket, head) => {
|
|
130
122
|
if (req.url && req.url.endsWith("/wisp/")) {
|
|
131
123
|
wisp.routeRequest(req, socket, head);
|
|
132
|
-
} else if (options.rammerhead
|
|
124
|
+
} else if (options.rammerhead && shouldRouteRh(req)) {
|
|
133
125
|
routeRhUpgrade(req, socket, head);
|
|
134
126
|
} else {
|
|
135
127
|
socket.end();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chemicaljs",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Easily create your own web proxy with no experience required.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@mercuryworkshop/scramjet": "^1.0.2",
|
|
17
17
|
"@titaniumnetwork-dev/ultraviolet": "^3.2.0",
|
|
18
18
|
"express": "^4.19.2",
|
|
19
|
-
"rammerhead": "
|
|
19
|
+
"rammerhead": "https://github.com/chemicaljs/chemical/raw/main/rammerhead.tgz",
|
|
20
20
|
"wisp-server-node": "^1.1.0"
|
|
21
21
|
}
|
|
22
22
|
}
|