@lobehub/chat 1.20.0 → 1.20.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/CHANGELOG.md +17 -0
- package/Dockerfile +36 -49
- package/Dockerfile.database +36 -53
- package/package.json +1 -1
- package/scripts/serverLauncher/startServer.js +181 -0
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,23 @@
|
|
2
2
|
|
3
3
|
# Changelog
|
4
4
|
|
5
|
+
### [Version 1.20.1](https://github.com/lobehub/lobe-chat/compare/v1.20.0...v1.20.1)
|
6
|
+
|
7
|
+
<sup>Released on **2024-09-27**</sup>
|
8
|
+
|
9
|
+
<br/>
|
10
|
+
|
11
|
+
<details>
|
12
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
13
|
+
|
14
|
+
</details>
|
15
|
+
|
16
|
+
<div align="right">
|
17
|
+
|
18
|
+
[](#readme-top)
|
19
|
+
|
20
|
+
</div>
|
21
|
+
|
5
22
|
## [Version 1.20.0](https://github.com/lobehub/lobe-chat/compare/v1.19.36...v1.20.0)
|
6
23
|
|
7
24
|
<sup>Released on **2024-09-27**</sup>
|
package/Dockerfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
## Base image for all
|
1
|
+
## Base image for all building stages
|
2
2
|
FROM node:20-slim AS base
|
3
3
|
|
4
4
|
ARG USE_CN_MIRROR
|
@@ -10,19 +10,22 @@ RUN \
|
|
10
10
|
if [ "${USE_CN_MIRROR:-false}" = "true" ]; then \
|
11
11
|
sed -i "s/deb.debian.org/mirrors.ustc.edu.cn/g" "/etc/apt/sources.list.d/debian.sources"; \
|
12
12
|
fi \
|
13
|
-
# Add required package
|
13
|
+
# Add required package
|
14
14
|
&& apt update \
|
15
|
-
&& apt install
|
16
|
-
|
17
|
-
&&
|
18
|
-
|
19
|
-
|
20
|
-
&&
|
21
|
-
|
22
|
-
&&
|
23
|
-
|
24
|
-
|
25
|
-
&&
|
15
|
+
&& apt install ca-certificates proxychains-ng -qy \
|
16
|
+
# Prepare required package to distroless
|
17
|
+
&& mkdir -p /distroless/bin /distroless/etc /distroless/etc/ssl/certs /distroless/lib \
|
18
|
+
# Copy proxychains to distroless
|
19
|
+
&& cp /usr/lib/$(arch)-linux-gnu/libproxychains.so.4 /distroless/lib/libproxychains.so.4 \
|
20
|
+
&& cp /usr/lib/$(arch)-linux-gnu/libdl.so.2 /distroless/lib/libdl.so.2 \
|
21
|
+
&& cp /usr/bin/proxychains4 /distroless/bin/proxychains \
|
22
|
+
&& cp /etc/proxychains4.conf /distroless/etc/proxychains4.conf \
|
23
|
+
# Copy node to distroless
|
24
|
+
&& cp /usr/lib/$(arch)-linux-gnu/libstdc++.so.6 /distroless/lib/libstdc++.so.6 \
|
25
|
+
&& cp /usr/lib/$(arch)-linux-gnu/libgcc_s.so.1 /distroless/lib/libgcc_s.so.1 \
|
26
|
+
&& cp /usr/local/bin/node /distroless/bin/node \
|
27
|
+
# Copy CA certificates to distroless
|
28
|
+
&& cp /etc/ssl/certs/ca-certificates.crt /distroless/etc/ssl/certs/ca-certificates.crt \
|
26
29
|
# Cleanup temp files
|
27
30
|
&& rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/*
|
28
31
|
|
@@ -80,7 +83,9 @@ COPY . .
|
|
80
83
|
RUN npm run build:docker
|
81
84
|
|
82
85
|
## Application image, copy all the files for production
|
83
|
-
FROM
|
86
|
+
FROM busybox:latest AS app
|
87
|
+
|
88
|
+
COPY --from=base /distroless/ /
|
84
89
|
|
85
90
|
COPY --from=builder /app/public /app/public
|
86
91
|
|
@@ -90,13 +95,25 @@ COPY --from=builder /app/.next/standalone /app/
|
|
90
95
|
COPY --from=builder /app/.next/static /app/.next/static
|
91
96
|
COPY --from=builder /deps/node_modules/.pnpm /app/node_modules/.pnpm
|
92
97
|
|
98
|
+
# Copy server launcher
|
99
|
+
COPY --from=builder /app/scripts/serverLauncher/startServer.js /app/startServer.js
|
100
|
+
|
101
|
+
RUN \
|
102
|
+
# Add nextjs:nodejs to run the app
|
103
|
+
addgroup -S -g 1001 nodejs \
|
104
|
+
&& adduser -D -G nodejs -H -S -h /app -u 1001 nextjs \
|
105
|
+
# Set permission for nextjs:nodejs
|
106
|
+
&& chown -R nextjs:nodejs /app /etc/proxychains4.conf
|
107
|
+
|
93
108
|
## Production image, copy all the files and run next
|
94
|
-
FROM
|
109
|
+
FROM scratch
|
95
110
|
|
96
111
|
# Copy all the files from app, set the correct permission for prerender cache
|
97
|
-
COPY --from=app
|
112
|
+
COPY --from=app / /
|
98
113
|
|
99
114
|
ENV NODE_ENV="production" \
|
115
|
+
NODE_OPTIONS="--use-openssl-ca" \
|
116
|
+
NODE_EXTRA_CA_CERTS="/etc/ssl/certs/ca-certificates.crt"
|
100
117
|
NODE_TLS_REJECT_UNAUTHORIZED=""
|
101
118
|
|
102
119
|
# set hostname to localhost
|
@@ -176,36 +193,6 @@ USER nextjs
|
|
176
193
|
|
177
194
|
EXPOSE 3210/tcp
|
178
195
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
IP_REGEX="^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$"; \
|
183
|
-
# Set proxychains command
|
184
|
-
PROXYCHAINS="proxychains -q"; \
|
185
|
-
# Parse the proxy URL
|
186
|
-
host_with_port="${PROXY_URL#*//}"; \
|
187
|
-
host="${host_with_port%%:*}"; \
|
188
|
-
port="${PROXY_URL##*:}"; \
|
189
|
-
protocol="${PROXY_URL%%://*}"; \
|
190
|
-
# Resolve to IP address if the host is a domain
|
191
|
-
if ! [[ "$host" =~ "$IP_REGEX" ]]; then \
|
192
|
-
nslookup=$(nslookup -q="A" "$host" | tail -n +3 | grep 'Address:'); \
|
193
|
-
if [ -n "$nslookup" ]; then \
|
194
|
-
host=$(echo "$nslookup" | tail -n 1 | awk '{print $2}'); \
|
195
|
-
fi; \
|
196
|
-
fi; \
|
197
|
-
# Generate proxychains configuration file
|
198
|
-
printf "%s\n" \
|
199
|
-
'localnet 127.0.0.0/255.0.0.0' \
|
200
|
-
'localnet ::1/128' \
|
201
|
-
'proxy_dns' \
|
202
|
-
'remote_dns_subnet 224' \
|
203
|
-
'strict_chain' \
|
204
|
-
'tcp_connect_time_out 8000' \
|
205
|
-
'tcp_read_time_out 15000' \
|
206
|
-
'[ProxyList]' \
|
207
|
-
"$protocol $host $port" \
|
208
|
-
> "/etc/proxychains4.conf"; \
|
209
|
-
fi; \
|
210
|
-
# Run the server
|
211
|
-
${PROXYCHAINS} node "/app/server.js";
|
196
|
+
ENTRYPOINT ["/bin/node"]
|
197
|
+
|
198
|
+
CMD ["/app/startServer.js"]
|
package/Dockerfile.database
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
## Base image for all
|
1
|
+
## Base image for all building stages
|
2
2
|
FROM node:20-slim AS base
|
3
3
|
|
4
4
|
ARG USE_CN_MIRROR
|
@@ -10,19 +10,22 @@ RUN \
|
|
10
10
|
if [ "${USE_CN_MIRROR:-false}" = "true" ]; then \
|
11
11
|
sed -i "s/deb.debian.org/mirrors.ustc.edu.cn/g" "/etc/apt/sources.list.d/debian.sources"; \
|
12
12
|
fi \
|
13
|
-
# Add required package
|
13
|
+
# Add required package
|
14
14
|
&& apt update \
|
15
|
-
&& apt install
|
16
|
-
|
17
|
-
&&
|
18
|
-
|
19
|
-
|
20
|
-
&&
|
21
|
-
|
22
|
-
&&
|
23
|
-
|
24
|
-
|
25
|
-
&&
|
15
|
+
&& apt install ca-certificates proxychains-ng -qy \
|
16
|
+
# Prepare required package to distroless
|
17
|
+
&& mkdir -p /distroless/bin /distroless/etc /distroless/etc/ssl/certs /distroless/lib \
|
18
|
+
# Copy proxychains to distroless
|
19
|
+
&& cp /usr/lib/$(arch)-linux-gnu/libproxychains.so.4 /distroless/lib/libproxychains.so.4 \
|
20
|
+
&& cp /usr/lib/$(arch)-linux-gnu/libdl.so.2 /distroless/lib/libdl.so.2 \
|
21
|
+
&& cp /usr/bin/proxychains4 /distroless/bin/proxychains \
|
22
|
+
&& cp /etc/proxychains4.conf /distroless/etc/proxychains4.conf \
|
23
|
+
# Copy node to distroless
|
24
|
+
&& cp /usr/lib/$(arch)-linux-gnu/libstdc++.so.6 /distroless/lib/libstdc++.so.6 \
|
25
|
+
&& cp /usr/lib/$(arch)-linux-gnu/libgcc_s.so.1 /distroless/lib/libgcc_s.so.1 \
|
26
|
+
&& cp /usr/local/bin/node /distroless/bin/node \
|
27
|
+
# Copy CA certificates to distroless
|
28
|
+
&& cp /etc/ssl/certs/ca-certificates.crt /distroless/etc/ssl/certs/ca-certificates.crt \
|
26
29
|
# Cleanup temp files
|
27
30
|
&& rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/*
|
28
31
|
|
@@ -84,7 +87,9 @@ COPY . .
|
|
84
87
|
RUN npm run build:docker
|
85
88
|
|
86
89
|
## Application image, copy all the files for production
|
87
|
-
FROM
|
90
|
+
FROM busybox:latest AS app
|
91
|
+
|
92
|
+
COPY --from=base /distroless/ /
|
88
93
|
|
89
94
|
COPY --from=builder /app/public /app/public
|
90
95
|
|
@@ -103,13 +108,25 @@ COPY --from=builder /app/src/database/server/migrations /app/migrations
|
|
103
108
|
COPY --from=builder /app/scripts/migrateServerDB/docker.cjs /app/docker.cjs
|
104
109
|
COPY --from=builder /app/scripts/migrateServerDB/errorHint.js /app/errorHint.js
|
105
110
|
|
111
|
+
# Copy server launcher
|
112
|
+
COPY --from=builder /app/scripts/serverLauncher/startServer.js /app/startServer.js
|
113
|
+
|
114
|
+
RUN \
|
115
|
+
# Add nextjs:nodejs to run the app
|
116
|
+
addgroup -S -g 1001 nodejs \
|
117
|
+
&& adduser -D -G nodejs -H -S -h /app -u 1001 nextjs \
|
118
|
+
# Set permission for nextjs:nodejs
|
119
|
+
&& chown -R nextjs:nodejs /app /etc/proxychains4.conf
|
120
|
+
|
106
121
|
## Production image, copy all the files and run next
|
107
|
-
FROM
|
122
|
+
FROM scratch
|
108
123
|
|
109
124
|
# Copy all the files from app, set the correct permission for prerender cache
|
110
|
-
COPY --from=app
|
125
|
+
COPY --from=app / /
|
111
126
|
|
112
127
|
ENV NODE_ENV="production" \
|
128
|
+
NODE_OPTIONS="--use-openssl-ca" \
|
129
|
+
NODE_EXTRA_CA_CERTS="/etc/ssl/certs/ca-certificates.crt"
|
113
130
|
NODE_TLS_REJECT_UNAUTHORIZED=""
|
114
131
|
|
115
132
|
# set hostname to localhost
|
@@ -208,40 +225,6 @@ USER nextjs
|
|
208
225
|
|
209
226
|
EXPOSE 3210/tcp
|
210
227
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
IP_REGEX="^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$"; \
|
215
|
-
# Set proxychains command
|
216
|
-
PROXYCHAINS="proxychains -q"; \
|
217
|
-
# Parse the proxy URL
|
218
|
-
host_with_port="${PROXY_URL#*//}"; \
|
219
|
-
host="${host_with_port%%:*}"; \
|
220
|
-
port="${PROXY_URL##*:}"; \
|
221
|
-
protocol="${PROXY_URL%%://*}"; \
|
222
|
-
# Resolve to IP address if the host is a domain
|
223
|
-
if ! [[ "$host" =~ "$IP_REGEX" ]]; then \
|
224
|
-
nslookup=$(nslookup -q="A" "$host" | tail -n +3 | grep 'Address:'); \
|
225
|
-
if [ -n "$nslookup" ]; then \
|
226
|
-
host=$(echo "$nslookup" | tail -n 1 | awk '{print $2}'); \
|
227
|
-
fi; \
|
228
|
-
fi; \
|
229
|
-
# Generate proxychains configuration file
|
230
|
-
printf "%s\n" \
|
231
|
-
'localnet 127.0.0.0/255.0.0.0' \
|
232
|
-
'localnet ::1/128' \
|
233
|
-
'proxy_dns' \
|
234
|
-
'remote_dns_subnet 224' \
|
235
|
-
'strict_chain' \
|
236
|
-
'tcp_connect_time_out 8000' \
|
237
|
-
'tcp_read_time_out 15000' \
|
238
|
-
'[ProxyList]' \
|
239
|
-
"$protocol $host $port" \
|
240
|
-
> "/etc/proxychains4.conf"; \
|
241
|
-
fi; \
|
242
|
-
# Run migration
|
243
|
-
node "/app/docker.cjs"; \
|
244
|
-
if [ "$?" -eq "0" ]; then \
|
245
|
-
# Run the server
|
246
|
-
${PROXYCHAINS} node "/app/server.js"; \
|
247
|
-
fi;
|
228
|
+
ENTRYPOINT ["/bin/node"]
|
229
|
+
|
230
|
+
CMD ["/app/startServer.js"]
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lobehub/chat",
|
3
|
-
"version": "1.20.
|
3
|
+
"version": "1.20.1",
|
4
4
|
"description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
|
5
5
|
"keywords": [
|
6
6
|
"framework",
|
@@ -0,0 +1,181 @@
|
|
1
|
+
const dns = require('dns').promises;
|
2
|
+
const fs = require('fs');
|
3
|
+
const tls = require('tls');
|
4
|
+
const { spawn } = require('child_process');
|
5
|
+
|
6
|
+
// Set file paths
|
7
|
+
const DB_MIGRATION_SCRIPT_PATH = '/app/docker.cjs';
|
8
|
+
const SERVER_SCRIPT_PATH = '/app/server.js';
|
9
|
+
const PROXYCHAINS_CONF_PATH = '/etc/proxychains4.conf';
|
10
|
+
|
11
|
+
// Function to check if a string is a valid IP address
|
12
|
+
const isValidIP = (ip, version = 4) => {
|
13
|
+
const ipv4Regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/;
|
14
|
+
const ipv6Regex = /^(([0-9a-f]{1,4}:){7,7}[0-9a-f]{1,4}|([0-9a-f]{1,4}:){1,7}:|([0-9a-f]{1,4}:){1,6}:[0-9a-f]{1,4}|([0-9a-f]{1,4}:){1,5}(:[0-9a-f]{1,4}){1,2}|([0-9a-f]{1,4}:){1,4}(:[0-9a-f]{1,4}){1,3}|([0-9a-f]{1,4}:){1,3}(:[0-9a-f]{1,4}){1,4}|([0-9a-f]{1,4}:){1,2}(:[0-9a-f]{1,4}){1,5}|[0-9a-f]{1,4}:((:[0-9a-f]{1,4}){1,6})|:((:[0-9a-f]{1,4}){1,7}|:)|fe80:(:[0-9a-f]{0,4}){0,4}%[0-9a-z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-f]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
15
|
+
|
16
|
+
switch (version) {
|
17
|
+
case 4:
|
18
|
+
return ipv4Regex.test(ip);
|
19
|
+
case 6:
|
20
|
+
return ipv6Regex.test(ip);
|
21
|
+
default:
|
22
|
+
return ipv4Regex.test(ip) || ipv6Regex.test(ip);
|
23
|
+
}
|
24
|
+
};
|
25
|
+
|
26
|
+
// Function to check TLS validity of a URL
|
27
|
+
const isValidTLS = (url = '') => {
|
28
|
+
if (!url) {
|
29
|
+
console.log('⚠️ TLS Check: No URL provided. Skipping TLS check. Ensure correct setting ENV.');
|
30
|
+
console.log('-------------------------------------');
|
31
|
+
return Promise.resolve();
|
32
|
+
}
|
33
|
+
|
34
|
+
const { protocol, host, port } = parseUrl(url);
|
35
|
+
if (protocol !== 'https') {
|
36
|
+
console.log(`⚠️ TLS Check: Non-HTTPS protocol (${protocol}). Skipping TLS check for ${url}.`);
|
37
|
+
console.log('-------------------------------------');
|
38
|
+
return Promise.resolve();
|
39
|
+
}
|
40
|
+
|
41
|
+
const options = { host, port, servername: host };
|
42
|
+
return new Promise((resolve, reject) => {
|
43
|
+
const socket = tls.connect(options, () => {
|
44
|
+
if (socket.authorized) {
|
45
|
+
console.log(`✅ TLS Check: Valid certificate for ${host}:${port}.`);
|
46
|
+
console.log('-------------------------------------');
|
47
|
+
resolve();
|
48
|
+
}
|
49
|
+
socket.end();
|
50
|
+
});
|
51
|
+
|
52
|
+
socket.on('error', (err) => {
|
53
|
+
const errMsg = `❌ TLS Check: Error for ${host}:${port}. Details:`;
|
54
|
+
switch (err.code) {
|
55
|
+
case 'CERT_HAS_EXPIRED':
|
56
|
+
case 'DEPTH_ZERO_SELF_SIGNED_CERT':
|
57
|
+
console.error(`${errMsg} Certificate is not valid. Consider setting NODE_TLS_REJECT_UNAUTHORIZED="0" or mapping /etc/ssl/certs/ca-certificates.crt.`);
|
58
|
+
break;
|
59
|
+
case 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY':
|
60
|
+
console.error(`${errMsg} Unable to verify issuer. Ensure correct mapping of /etc/ssl/certs/ca-certificates.crt.`);
|
61
|
+
break;
|
62
|
+
default:
|
63
|
+
console.error(`${errMsg} Network issue. Check firewall or DNS.`);
|
64
|
+
break;
|
65
|
+
}
|
66
|
+
reject(err);
|
67
|
+
});
|
68
|
+
});
|
69
|
+
};
|
70
|
+
|
71
|
+
// Function to check TLS connections for OSS and Auth Issuer
|
72
|
+
const checkTLSConnections = async () => {
|
73
|
+
await Promise.all([
|
74
|
+
isValidTLS(process.env.S3_ENDPOINT),
|
75
|
+
isValidTLS(process.env.S3_PUBLIC_DOMAIN),
|
76
|
+
isValidTLS(getEnvVarsByKeyword('_ISSUER')),
|
77
|
+
]);
|
78
|
+
};
|
79
|
+
|
80
|
+
// Function to get environment variable by keyword
|
81
|
+
const getEnvVarsByKeyword = (keyword) => {
|
82
|
+
return Object.entries(process.env)
|
83
|
+
.filter(([key, value]) => key.includes(keyword) && value)
|
84
|
+
.map(([, value]) => value)[0] || null;
|
85
|
+
};
|
86
|
+
|
87
|
+
// Function to parse protocol, host and port from a URL
|
88
|
+
const parseUrl = (url) => {
|
89
|
+
const { protocol, hostname: host, port } = new URL(url);
|
90
|
+
return { protocol: protocol.replace(':', ''), host, port: port || 443 };
|
91
|
+
};
|
92
|
+
|
93
|
+
// Function to resolve host IP via DNS
|
94
|
+
const resolveHostIP = async (host, version = 4) => {
|
95
|
+
try {
|
96
|
+
const { address } = await dns.lookup(host, { family: version });
|
97
|
+
|
98
|
+
if (!isValidIP(address, version)) {
|
99
|
+
console.error(`❌ DNS Error: Invalid resolved IP: ${address}. IP address must be IPv${version}.`);
|
100
|
+
process.exit(1);
|
101
|
+
}
|
102
|
+
|
103
|
+
return address;
|
104
|
+
} catch (err) {
|
105
|
+
console.error(`❌ DNS Error: Could not resolve ${host}. Check DNS server.`, err);
|
106
|
+
process.exit(1);
|
107
|
+
}
|
108
|
+
};
|
109
|
+
|
110
|
+
// Function to generate proxychains configuration
|
111
|
+
const runProxyChainsConfGenerator = async (url) => {
|
112
|
+
const { protocol, host, port } = parseUrl(url);
|
113
|
+
|
114
|
+
if (!['http', 'socks4', 'socks5'].includes(protocol)) {
|
115
|
+
console.error(`❌ ProxyChains: Invalid protocol (${protocol}). Protocol must be 'http', 'socks4' and 'socks5'.`);
|
116
|
+
process.exit(1);
|
117
|
+
}
|
118
|
+
|
119
|
+
const validPort = parseInt(port, 10);
|
120
|
+
if (isNaN(validPort) || validPort <= 0 || validPort > 65535) {
|
121
|
+
console.error(`❌ ProxyChains: Invalid port (${port}). Port must be a number between 1 and 65535.`);
|
122
|
+
process.exit(1);
|
123
|
+
}
|
124
|
+
|
125
|
+
let ip = isValidIP(host, 4) ? host : await resolveHostIP(host, 4);
|
126
|
+
|
127
|
+
const configContent = `
|
128
|
+
localnet 127.0.0.0/255.0.0.0
|
129
|
+
localnet ::1/128
|
130
|
+
proxy_dns
|
131
|
+
remote_dns_subnet 224
|
132
|
+
strict_chain
|
133
|
+
tcp_connect_time_out 8000
|
134
|
+
tcp_read_time_out 15000
|
135
|
+
[ProxyList]
|
136
|
+
${protocol} ${ip} ${port}
|
137
|
+
`.trim();
|
138
|
+
|
139
|
+
fs.writeFileSync(PROXYCHAINS_CONF_PATH, configContent);
|
140
|
+
console.log(`✅ ProxyChains: All outgoing traffic routed via ${protocol}://${ip}:${port}.`);
|
141
|
+
console.log('-------------------------------------');
|
142
|
+
};
|
143
|
+
|
144
|
+
// Function to execute a script with child process spawn
|
145
|
+
const runScript = (scriptPath, useProxy = false) => {
|
146
|
+
const command = useProxy ? ['/bin/proxychains', '-q', '/bin/node', scriptPath] : ['/bin/node', scriptPath];
|
147
|
+
return new Promise((resolve, reject) => {
|
148
|
+
const process = spawn(command.shift(), command, { stdio: 'inherit' });
|
149
|
+
process.on('close', (code) => (code === 0 ? resolve() : reject(new Error(`🔴 Process exited with code ${code}`))));
|
150
|
+
});
|
151
|
+
};
|
152
|
+
|
153
|
+
// Main function to run the server with optional proxy
|
154
|
+
const runServer = async () => {
|
155
|
+
const PROXY_URL = process.env.PROXY_URL || ''; // Default empty string to avoid undefined errors
|
156
|
+
|
157
|
+
if (PROXY_URL) {
|
158
|
+
await runProxyChainsConfGenerator(PROXY_URL);
|
159
|
+
return runScript(SERVER_SCRIPT_PATH, true);
|
160
|
+
}
|
161
|
+
return runScript(SERVER_SCRIPT_PATH);
|
162
|
+
};
|
163
|
+
|
164
|
+
// Main execution block
|
165
|
+
(async () => {
|
166
|
+
console.log('🌐 DNS Server:', dns.getServers());
|
167
|
+
console.log('-------------------------------------');
|
168
|
+
|
169
|
+
if (process.env.DATABASE_DRIVER) {
|
170
|
+
try {
|
171
|
+
await runScript(DB_MIGRATION_SCRIPT_PATH);
|
172
|
+
await checkTLSConnections();
|
173
|
+
} catch (err) {
|
174
|
+
console.error('❌ Error during DB migration or TLS connection check:', err);
|
175
|
+
process.exit(1);
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
// Run the server in either database or non-database mode
|
180
|
+
await runServer();
|
181
|
+
})();
|