Skip to content

Commit 4a3cc1a

Browse files
authored
Initial commit
0 parents  commit 4a3cc1a

File tree

4 files changed

+347
-0
lines changed

4 files changed

+347
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This is barebones version of https://github.com/fscarmen2/Argo-Xray-JS-PaaS without CF Argo, Nezha and other bells and whistles, as I don't need that.
2+
Also added SERVICE_URL environment variable for ease of deploying between various services, which have each own variable for external url, and you don't need to remember them.
3+
You can change UUID, WSPATH and PORT via variables like in original project, but if you just want to deploy and test this, you can leave it like that.

entrypoint.sh

+208
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
#!/usr/bin/env bash
2+
3+
WSPATH=${WSPATH:-'xray'}
4+
UUID=${UUID:-'de04add9-5c68-8bab-950c-08cd5320df18'}
5+
6+
check_dependencies() {
7+
DEPS_CHECK=("wget" "unzip")
8+
DEPS_INSTALL=(" wget" " unzip")
9+
for ((i=0;i<${#DEPS_CHECK[@]};i++)); do [[ ! $(type -p ${DEPS_CHECK[i]}) ]] && DEPS+=${DEPS_INSTALL[i]}; done
10+
[ -n "$DEPS" ] && { apt-get update >/dev/null 2>&1; apt-get install -y $DEPS >/dev/null 2>&1; }
11+
}
12+
13+
generate_config() {
14+
cat > config.json << EOF
15+
{
16+
"log":{
17+
"access":"/dev/null",
18+
"error":"/dev/null",
19+
"loglevel":"none"
20+
},
21+
"inbounds":[
22+
{
23+
"port":8080,
24+
"protocol":"vless",
25+
"settings":{
26+
"clients":[
27+
{
28+
"id":"${UUID}",
29+
"flow":"xtls-rprx-vision"
30+
}
31+
],
32+
"decryption":"none",
33+
"fallbacks":[
34+
{
35+
"dest":3001
36+
},
37+
{
38+
"path":"/${WSPATH}-vless",
39+
"dest":3002
40+
},
41+
{
42+
"path":"/${WSPATH}-vmess",
43+
"dest":3003
44+
},
45+
{
46+
"path":"/${WSPATH}-trojan",
47+
"dest":3004
48+
},
49+
{
50+
"path":"/${WSPATH}-shadowsocks",
51+
"dest":3005
52+
}
53+
]
54+
},
55+
"streamSettings":{
56+
"network":"tcp"
57+
}
58+
},
59+
{
60+
"port":3001,
61+
"listen":"127.0.0.1",
62+
"protocol":"vless",
63+
"settings":{
64+
"clients":[
65+
{
66+
"id":"${UUID}"
67+
}
68+
],
69+
"decryption":"none"
70+
},
71+
"streamSettings":{
72+
"network":"ws",
73+
"security":"none"
74+
}
75+
},
76+
{
77+
"port":3002,
78+
"listen":"127.0.0.1",
79+
"protocol":"vless",
80+
"settings":{
81+
"clients":[
82+
{
83+
"id":"${UUID}",
84+
"level":0
85+
}
86+
],
87+
"decryption":"none"
88+
},
89+
"streamSettings":{
90+
"network":"ws",
91+
"security":"none",
92+
"wsSettings":{
93+
"path":"/${WSPATH}-vless"
94+
}
95+
},
96+
"sniffing":{
97+
"enabled":true,
98+
"destOverride":[
99+
"http",
100+
"tls",
101+
"quic"
102+
],
103+
"metadataOnly":false
104+
}
105+
},
106+
{
107+
"port":3003,
108+
"listen":"127.0.0.1",
109+
"protocol":"vmess",
110+
"settings":{
111+
"clients":[
112+
{
113+
"id":"${UUID}",
114+
"alterId":0
115+
}
116+
]
117+
},
118+
"streamSettings":{
119+
"network":"ws",
120+
"wsSettings":{
121+
"path":"/${WSPATH}-vmess"
122+
}
123+
},
124+
"sniffing":{
125+
"enabled":true,
126+
"destOverride":[
127+
"http",
128+
"tls",
129+
"quic"
130+
],
131+
"metadataOnly":false
132+
}
133+
},
134+
{
135+
"port":3004,
136+
"listen":"127.0.0.1",
137+
"protocol":"trojan",
138+
"settings":{
139+
"clients":[
140+
{
141+
"password":"${UUID}"
142+
}
143+
]
144+
},
145+
"streamSettings":{
146+
"network":"ws",
147+
"security":"none",
148+
"wsSettings":{
149+
"path":"/${WSPATH}-trojan"
150+
}
151+
},
152+
"sniffing":{
153+
"enabled":true,
154+
"destOverride":[
155+
"http",
156+
"tls",
157+
"quic"
158+
],
159+
"metadataOnly":false
160+
}
161+
},
162+
{
163+
"port":3005,
164+
"listen":"127.0.0.1",
165+
"protocol":"shadowsocks",
166+
"settings":{
167+
"clients":[
168+
{
169+
"method":"chacha20-ietf-poly1305",
170+
"password":"${UUID}"
171+
}
172+
],
173+
"decryption":"none"
174+
},
175+
"streamSettings":{
176+
"network":"ws",
177+
"wsSettings":{
178+
"path":"/${WSPATH}-shadowsocks"
179+
}
180+
},
181+
"sniffing":{
182+
"enabled":true,
183+
"destOverride":[
184+
"http",
185+
"tls",
186+
"quic"
187+
],
188+
"metadataOnly":false
189+
}
190+
}
191+
],
192+
"dns":{
193+
"servers":[
194+
"https+local://8.8.8.8/dns-query"
195+
]
196+
},
197+
"outbounds":[
198+
{
199+
"protocol":"freedom"
200+
}
201+
]
202+
}
203+
EOF
204+
}
205+
206+
check_dependencies
207+
generate_config
208+
wait

package.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "express-hello-world",
3+
"version": "1.0.0",
4+
"description": "Express Hello World",
5+
"main": "server.js",
6+
"repository": "https://github.com/fscarmen2/Argo-X-JS-PaaS",
7+
"author": "fscarmen",
8+
"license": "MIT",
9+
"private": false,
10+
"scripts": {
11+
"start": "node server.js"
12+
},
13+
"dependencies": {
14+
"express": "^4.18.2",
15+
"http-proxy-middleware": "^2.0.6",
16+
"request": "^2.88.2",
17+
},
18+
"engines": {
19+
"node": ">=14"
20+
}
21+
}

server.js

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
const url = "https://" + process.env.SERVICE_URL;
2+
const port = process.env.PORT || 3000;
3+
const express = require("express");
4+
const app = express();
5+
var exec = require("child_process").exec;
6+
const { createProxyMiddleware } = require("http-proxy-middleware");
7+
var request = require("request");
8+
var fs = require("fs");
9+
var path = require("path");
10+
11+
app.get("/", function (req, res) {
12+
res.send("hello world");
13+
});
14+
15+
app.get("/start", function (req, res) {
16+
let cmdStr = "[ -e entrypoint.sh ] && bash entrypoint.sh; chmod +x ./web.js && ./web.js -c ./config.json >/dev/null 2>&1 &";
17+
exec(cmdStr, function (err, stdout, stderr) {
18+
if (err) {
19+
res.send("Web start error:" + err);
20+
}
21+
else {
22+
res.send("Web start success!");
23+
}
24+
});
25+
});
26+
27+
// keepalive begin
28+
function keepalive() {
29+
exec("curl -m8 " + url + ":" + port, function (err, stdout, stderr) {
30+
if (err) {
31+
console.log("Keepalive error: " + err);
32+
} else {
33+
console.log("Keepalive success, response:" + stdout);
34+
}
35+
});
36+
37+
exec("pgrep -laf web.js", function (err, stdout, stderr) {
38+
if (stdout.includes("./web.js -c ./config.json")) {
39+
console.log("Web service is working");
40+
}
41+
else {
42+
exec(
43+
"chmod +x web.js && ./web.js -c ./config.json >/dev/null 2>&1 &", function (err, stdout, stderr) {
44+
if (err) {
45+
console.log("Keepalive restart error:" + err);
46+
}
47+
else {
48+
console.log("Keepalive restart success!");
49+
}
50+
}
51+
);
52+
}
53+
});
54+
}
55+
setInterval(keepalive, 10 * 1000);
56+
57+
app.get("/download", function (req, res) {
58+
download_web((err) => {
59+
if (err) {
60+
res.send("web.js downloaded successfully!");
61+
}
62+
else {
63+
res.send("web.js download failed: " + err);
64+
}
65+
});
66+
});
67+
68+
app.use(
69+
"/",
70+
createProxyMiddleware({
71+
changeOrigin: true,
72+
onProxyReq: function onProxyReq(proxyReq, req, res) {},
73+
pathRewrite: {
74+
"^/": "/"
75+
},
76+
target: "http://127.0.0.1:8080/",
77+
ws: true
78+
})
79+
);
80+
81+
function download_web(callback) {
82+
let fileName = "web.js";
83+
let web_url =
84+
"https://github.com/fscarmen2/Argo-X-Container-PaaS/raw/main/web.js";
85+
let stream = fs.createWriteStream(path.join("./", fileName));
86+
request(web_url)
87+
.pipe(stream)
88+
.on("close", function (err) {
89+
if (err) {
90+
callback("Failed to download web.js: " + err);
91+
}
92+
else {
93+
callback(null);
94+
}
95+
});
96+
}
97+
98+
download_web((err) => {
99+
if (err) {
100+
console.log("Failed to download web.js: " + err);
101+
}
102+
else {
103+
console.log("web.js downloaded successfully!");
104+
}
105+
});
106+
107+
exec("bash entrypoint.sh", function (err, stdout, stderr) {
108+
if (err) {
109+
console.error(err);
110+
return;
111+
}
112+
console.log(stdout);
113+
});
114+
115+
app.listen(port, () => console.log(`Example app listening on port ${port}!`));

0 commit comments

Comments
 (0)