chemicaljs 1.2.0 → 1.2.2
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 +30 -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()
|
|
@@ -65,45 +81,23 @@ class ChemicalServer {
|
|
|
65
81
|
chemicalMain = `const defaultService = "uv";\n\n` + chemicalMain
|
|
66
82
|
console.error("Error: Chemical default option invalid.")
|
|
67
83
|
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (options.uv == false) {
|
|
71
|
-
chemicalMain = "const uvEnabled = false;\n" + chemicalMain
|
|
72
|
-
} else {
|
|
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
84
|
} else {
|
|
83
|
-
chemicalMain =
|
|
85
|
+
chemicalMain = `const defaultService = "uv";\n\n` + chemicalMain;
|
|
84
86
|
}
|
|
85
87
|
|
|
88
|
+
chemicalMain = "const uvEnabled = " + String(options.uv) + ";\n" + chemicalMain
|
|
89
|
+
chemicalMain = "const scramjetEnabled = " + String(options.scramjet) + ";\n" + chemicalMain
|
|
90
|
+
chemicalMain = "const rammerheadEnabled = " + String(options.rammerhead) + ";\n" + chemicalMain
|
|
91
|
+
|
|
86
92
|
res.type("application/javascript");
|
|
87
93
|
return res.send(chemicalMain);
|
|
88
94
|
});
|
|
89
95
|
this.app.get("/chemical.sw.js", async function (req, res) {
|
|
90
96
|
let chemicalSW = await readFileSync(resolve(import.meta.dirname, "client/chemical.sw.js"), "utf8");
|
|
91
97
|
|
|
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
|
-
}
|
|
98
|
+
chemicalSW = "const uvEnabled = " + String(options.uv) + ";\n" + chemicalSW
|
|
99
|
+
chemicalSW = "const scramjetEnabled = " + String(options.scramjet) + ";\n" + chemicalSW
|
|
100
|
+
chemicalSW = "const rammerheadEnabled = " + String(options.rammerhead) + ";\n" + chemicalSW
|
|
107
101
|
|
|
108
102
|
res.type("application/javascript");
|
|
109
103
|
return res.send(chemicalSW);
|
|
@@ -111,16 +105,16 @@ class ChemicalServer {
|
|
|
111
105
|
this.app.use(express.static(resolve(import.meta.dirname, "client")));
|
|
112
106
|
this.app.use("/baremux/", express.static(baremuxPath));
|
|
113
107
|
this.app.use("/epoxy/", express.static(epoxyPath));
|
|
114
|
-
if (options.uv
|
|
108
|
+
if (options.uv) {
|
|
115
109
|
this.app.use("/uv/", express.static(resolve(import.meta.dirname, "config/uv")));
|
|
116
110
|
this.app.use("/uv/", express.static(uvPath));
|
|
117
111
|
}
|
|
118
|
-
if (options.scramjet
|
|
112
|
+
if (options.scramjet) {
|
|
119
113
|
this.app.use("/scramjet/", express.static(resolve(import.meta.dirname, "config/scramjet")));
|
|
120
114
|
this.app.use("/scramjet/", express.static(scramjetPath));
|
|
121
115
|
}
|
|
122
116
|
this.server.on("request", (req, res) => {
|
|
123
|
-
if (options.rammerhead
|
|
117
|
+
if (options.rammerhead && shouldRouteRh(req)) {
|
|
124
118
|
routeRhRequest(req, res);
|
|
125
119
|
} else {
|
|
126
120
|
this.app(req, res);
|
|
@@ -129,7 +123,7 @@ class ChemicalServer {
|
|
|
129
123
|
this.server.on("upgrade", (req, socket, head) => {
|
|
130
124
|
if (req.url && req.url.endsWith("/wisp/")) {
|
|
131
125
|
wisp.routeRequest(req, socket, head);
|
|
132
|
-
} else if (options.rammerhead
|
|
126
|
+
} else if (options.rammerhead && shouldRouteRh(req)) {
|
|
133
127
|
routeRhUpgrade(req, socket, head);
|
|
134
128
|
} else {
|
|
135
129
|
socket.end();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chemicaljs",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
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
|
}
|