unplugin-https-reverse-proxy 2.0.2 → 2.0.3-beta.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.
@@ -1,314 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (let key of __getOwnPropNames(from))
11
- if (!__hasOwnProp.call(to, key) && key !== except)
12
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- }
14
- return to;
15
- };
16
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
- // If the importer is in node compatibility mode or this is not an ESM
18
- // file that has been converted to a CommonJS file using a Babel-
19
- // compatible transform (i.e. "__esModule" has not been set), then set
20
- // "default" to the CommonJS "module.exports" for node compatibility.
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
-
25
- // scripts/postinstall.ts
26
- var import_node_fs3 = require("fs");
27
- var import_node_process5 = __toESM(require("process"), 1);
28
-
29
- // src/caddy/index.ts
30
- var import_node_child_process4 = require("child_process");
31
- var import_node_fs2 = require("fs");
32
- var import_promises2 = require("fs/promises");
33
- var import_node_os3 = require("os");
34
- var import_node_path3 = require("path");
35
- var import_node_process4 = __toESM(require("process"), 1);
36
- var import_got_cjs = require("got-cjs");
37
- var import_http_proxy_agent = require("http-proxy-agent");
38
- var import_https_proxy_agent = require("https-proxy-agent");
39
- var lockfile = __toESM(require("proper-lockfile"), 1);
40
-
41
- // src/host/index.ts
42
- var import_node_child_process2 = require("child_process");
43
- var import_node_fs = require("fs");
44
- var import_node_process2 = __toESM(require("process"), 1);
45
- var import_node_util = require("util");
46
- var import_hostile = __toESM(require("hostile"), 1);
47
-
48
- // src/utils.ts
49
- var import_node_child_process = require("child_process");
50
- var import_promises = require("fs/promises");
51
- var import_node_os = require("os");
52
- var import_node_path = __toESM(require("path"), 1);
53
- var import_node_process = __toESM(require("process"), 1);
54
- var import_consola = require("consola");
55
- var import_picocolors = __toESM(require("picocolors"), 1);
56
- var import_qrcode_terminal = __toESM(require("qrcode-terminal"), 1);
57
- var consola = (0, import_consola.createConsola)({
58
- level: 3
59
- }).withTag("reverse-proxy");
60
- function once(fn) {
61
- let called = false;
62
- return (...args) => {
63
- if (called)
64
- return;
65
- called = true;
66
- return fn(...args);
67
- };
68
- }
69
-
70
- // src/host/index.ts
71
- var _setHost = (0, import_node_util.promisify)(import_hostile.default.set);
72
- var _removeHost = (0, import_node_util.promisify)(import_hostile.default.remove);
73
-
74
- // src/caddy/constants.ts
75
- var import_node_os2 = __toESM(require("os"), 1);
76
- var import_node_path2 = require("path");
77
- var import_node_process3 = __toESM(require("process"), 1);
78
- var import_dotenv_flow = __toESM(require("dotenv-flow"), 1);
79
- import_dotenv_flow.default.config({
80
- silent: true
81
- });
82
- function resolvePath(path2) {
83
- if (path2.startsWith("~"))
84
- return (0, import_node_path2.join)(import_node_os2.default.homedir() || "", path2.slice(1));
85
- return path2;
86
- }
87
- var TEMP_DIR = resolvePath(import_node_process3.default.env.UHRP_CADDY_PATH || import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp");
88
- var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
89
- var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
90
- var caddyLockFilePath = (0, import_node_path2.join)(TEMP_DIR, "caddylock");
91
- var supportList = [
92
- {
93
- platform: "dragonfly",
94
- arch: "amd64"
95
- },
96
- {
97
- platform: "freebsd",
98
- arch: "amd64"
99
- },
100
- {
101
- platform: "freebsd",
102
- arch: "arm-6"
103
- },
104
- {
105
- platform: "freebsd",
106
- arch: "arm-7"
107
- },
108
- {
109
- platform: "freebsd",
110
- arch: "arm64"
111
- },
112
- {
113
- platform: "linux",
114
- arch: "amd64"
115
- },
116
- {
117
- platform: "linux",
118
- arch: "arm-5"
119
- },
120
- {
121
- platform: "linux",
122
- arch: "arm-6"
123
- },
124
- {
125
- platform: "linux",
126
- arch: "arm-7"
127
- },
128
- {
129
- platform: "linux",
130
- arch: "arm64"
131
- },
132
- {
133
- platform: "linux",
134
- arch: "mips"
135
- },
136
- {
137
- platform: "linux",
138
- arch: "mips64"
139
- },
140
- {
141
- platform: "linux",
142
- arch: "mips64le"
143
- },
144
- {
145
- platform: "linux",
146
- arch: "mipsle"
147
- },
148
- {
149
- platform: "linux",
150
- arch: "ppc64"
151
- },
152
- {
153
- platform: "linux",
154
- arch: "ppc64le"
155
- },
156
- {
157
- platform: "linux",
158
- arch: "s390x"
159
- },
160
- {
161
- platform: "darwin",
162
- arch: "amd64"
163
- },
164
- {
165
- platform: "darwin",
166
- arch: "arm64"
167
- },
168
- {
169
- platform: "openbsd",
170
- arch: "amd64"
171
- },
172
- {
173
- platform: "openbsd",
174
- arch: "arm-6"
175
- },
176
- {
177
- platform: "openbsd",
178
- arch: "arm-7"
179
- },
180
- {
181
- platform: "openbsd",
182
- arch: "arm64"
183
- },
184
- {
185
- platform: "windows",
186
- arch: "amd64"
187
- },
188
- {
189
- platform: "windows",
190
- arch: "arm-6"
191
- },
192
- {
193
- platform: "windows",
194
- arch: "arm-7"
195
- },
196
- {
197
- platform: "windows",
198
- arch: "arm64"
199
- }
200
- ];
201
-
202
- // src/caddy/utils.ts
203
- var import_node_child_process3 = require("child_process");
204
- var import_node_net = require("net");
205
- var import_ora = __toESM(require("ora"), 1);
206
- var spinner;
207
- function getNumber(number) {
208
- if (number <= 0)
209
- return "0%";
210
- else if (number < 100)
211
- return `${number.toFixed(2)}%`;
212
- else
213
- return "100%";
214
- }
215
- function logProgress(percent) {
216
- if (!spinner) {
217
- consola.log("");
218
- spinner = (0, import_ora.default)({
219
- text: "Start Download Caddy: 0%",
220
- indent: 2
221
- });
222
- spinner.start();
223
- } else {
224
- spinner.text = `Download Caddy: ${getNumber(Number(percent) * 100)}`;
225
- }
226
- }
227
- function logProgressOver() {
228
- if (!spinner) {
229
- spinner = (0, import_ora.default)({
230
- text: "Start Download Caddy: 100%",
231
- indent: 2
232
- });
233
- spinner.start();
234
- } else {
235
- spinner.succeed();
236
- consola.log("");
237
- }
238
- }
239
-
240
- // src/caddy/index.ts
241
- async function download() {
242
- if (await testCaddy())
243
- return caddyPath;
244
- return new Promise((resolve, reject) => {
245
- if (!(0, import_node_fs2.existsSync)(TEMP_DIR)) {
246
- (0, import_node_fs2.mkdirSync)(TEMP_DIR, { recursive: true });
247
- (0, import_node_fs2.chmodSync)(TEMP_DIR, 511);
248
- }
249
- const file = (0, import_node_fs2.createWriteStream)(caddyPath);
250
- let _platform = (0, import_node_os3.platform)().toString();
251
- _platform === "win32" && (_platform = "windows");
252
- let _arch = import_node_process4.default.arch.toString();
253
- _arch === "x64" && (_arch = "amd64");
254
- const support = supportList.find((item) => item.platform === _platform && item.arch === _arch);
255
- if (!support)
256
- return reject(new Error("not support"));
257
- const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}&p=github.com%2Fcaddyserver%2Fforwardproxy`;
258
- (0, import_node_fs2.existsSync)(caddyPath) && (0, import_node_fs2.unlinkSync)(caddyPath);
259
- const httpProxy = import_node_process4.default.env.HTTP_PROXY || import_node_process4.default.env.http_proxy;
260
- const httpsProxy = import_node_process4.default.env.HTTPS_PROXY || import_node_process4.default.env.https_proxy;
261
- const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
262
- const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
263
- const chmodCaddyOnce = once(() => {
264
- (0, import_node_fs2.chmodSync)(caddyPath, 511);
265
- });
266
- import_got_cjs.got.stream(dowmloadLink, {
267
- agent: {
268
- http: httpAgent,
269
- https: httpsAgent
270
- }
271
- }).on("downloadProgress", (progress) => {
272
- logProgress(progress.percent);
273
- chmodCaddyOnce();
274
- }).pipe(file).on("finish", () => {
275
- logProgressOver();
276
- if (import_node_process4.default.platform === "win32")
277
- return resolve(caddyPath);
278
- (0, import_node_fs2.chmodSync)(caddyPath, 511);
279
- resolve(caddyPath);
280
- }).on("error", (err) => {
281
- reject(err);
282
- });
283
- });
284
- }
285
- function testCaddy() {
286
- return new Promise((resolve, reject) => {
287
- if (!(0, import_node_fs2.existsSync)(caddyPath))
288
- return resolve(false);
289
- (0, import_node_fs2.chmodSync)(caddyPath, 511);
290
- const child = import_node_process4.default.platform === "win32" ? (0, import_node_child_process4.spawn)(caddyPath, []) : (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath]);
291
- child.on("close", () => {
292
- return resolve(false);
293
- });
294
- child.on("error", (err) => {
295
- return reject(err);
296
- });
297
- child.stdout.on("data", (_data) => {
298
- return resolve(true);
299
- });
300
- });
301
- }
302
-
303
- // scripts/postinstall.ts
304
- async function run() {
305
- try {
306
- if (import_node_process5.default.env.UHRP_AUTO_INSTALL_CADDY) {
307
- (0, import_node_fs3.existsSync)(caddyPath) && (0, import_node_fs3.unlinkSync)(caddyPath);
308
- await download();
309
- }
310
- } catch (e) {
311
- consola.error(e.code);
312
- }
313
- }
314
- run();