unplugin-https-reverse-proxy 0.0.19 → 0.0.21
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/README.md +53 -17
- package/dist/{chunk-EAJJ2ZZG.js → chunk-3M3YENXO.js} +1 -1
- package/dist/{chunk-VOWRN6H5.js → chunk-CT3M7EPZ.js} +1 -1
- package/dist/{chunk-URF2UORY.js → chunk-NH3VM3RE.js} +15 -3
- package/dist/{chunk-CQC5SSJR.js → chunk-NNO3ZUSU.js} +16 -1
- package/dist/esbuild.cjs +59 -34
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +59 -34
- package/dist/index.js +2 -2
- package/dist/nuxt.cjs +59 -34
- package/dist/nuxt.js +4 -4
- package/dist/rollup.cjs +59 -34
- package/dist/rollup.js +2 -2
- package/dist/utils.cjs +26 -0
- package/dist/utils.d.cts +2 -1
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +3 -1
- package/dist/vite.cjs +59 -34
- package/dist/vite.js +3 -3
- package/dist/webpack.cjs +59 -34
- package/dist/webpack.js +3 -3
- package/package.json +1 -1
- package/src/index.ts +17 -3
- package/src/utils.ts +17 -0
package/dist/webpack.cjs
CHANGED
|
@@ -50,12 +50,14 @@ module.exports = __toCommonJS(webpack_exports);
|
|
|
50
50
|
var import_unplugin2 = require("unplugin");
|
|
51
51
|
|
|
52
52
|
// src/index.ts
|
|
53
|
-
var
|
|
53
|
+
var import_node_process4 = __toESM(require("process"), 1);
|
|
54
54
|
var import_node_fs2 = require("fs");
|
|
55
55
|
var import_unplugin = require("unplugin");
|
|
56
56
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
57
57
|
|
|
58
58
|
// src/utils.ts
|
|
59
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
60
|
+
var import_node_child_process = require("child_process");
|
|
59
61
|
var import_consola = require("consola");
|
|
60
62
|
var consola = (0, import_consola.createConsola)({
|
|
61
63
|
level: 3
|
|
@@ -69,12 +71,24 @@ function once(fn) {
|
|
|
69
71
|
return fn(...args);
|
|
70
72
|
};
|
|
71
73
|
}
|
|
74
|
+
function isAdmin() {
|
|
75
|
+
if (import_node_process.default.platform === "win32") {
|
|
76
|
+
try {
|
|
77
|
+
(0, import_node_child_process.execSync)("net session", { stdio: "ignore" });
|
|
78
|
+
return true;
|
|
79
|
+
} catch (e) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
return import_node_process.default.getuid && import_node_process.default.getuid() === 0;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
72
86
|
|
|
73
87
|
// src/caddy/index.ts
|
|
74
88
|
var import_node_os = require("os");
|
|
75
|
-
var
|
|
89
|
+
var import_node_process3 = __toESM(require("process"), 1);
|
|
76
90
|
var import_node_fs = require("fs");
|
|
77
|
-
var
|
|
91
|
+
var import_node_child_process2 = require("child_process");
|
|
78
92
|
var import_got_cjs = require("got-cjs");
|
|
79
93
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
80
94
|
var import_https_proxy_agent = require("https-proxy-agent");
|
|
@@ -83,9 +97,9 @@ var import_kill_port = __toESM(require("kill-port"), 1);
|
|
|
83
97
|
|
|
84
98
|
// src/caddy/constants.ts
|
|
85
99
|
var import_node_path = require("path");
|
|
86
|
-
var
|
|
87
|
-
var TEMP_DIR =
|
|
88
|
-
var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${
|
|
100
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
101
|
+
var TEMP_DIR = import_node_process2.default.env.TEMP || import_node_process2.default.env.TMPDIR || "/tmp";
|
|
102
|
+
var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process2.default.platform === "win32" ? ".exe" : ""}`);
|
|
89
103
|
var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
|
|
90
104
|
var supportList = [
|
|
91
105
|
{
|
|
@@ -262,15 +276,15 @@ async function download() {
|
|
|
262
276
|
const file = (0, import_node_fs.createWriteStream)(caddyPath);
|
|
263
277
|
let _platform = (0, import_node_os.platform)().toString();
|
|
264
278
|
_platform === "win32" && (_platform = "windows");
|
|
265
|
-
let _arch =
|
|
279
|
+
let _arch = import_node_process3.default.arch.toString();
|
|
266
280
|
_arch === "x64" && (_arch = "amd64");
|
|
267
281
|
const support = supportList.find((item) => item.platform === _platform && item.arch === _arch);
|
|
268
282
|
if (!support)
|
|
269
283
|
return reject(new Error("not support"));
|
|
270
284
|
const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}`;
|
|
271
285
|
(0, import_node_fs.existsSync)(caddyPath) && (0, import_node_fs.unlinkSync)(caddyPath);
|
|
272
|
-
const httpProxy =
|
|
273
|
-
const httpsProxy =
|
|
286
|
+
const httpProxy = import_node_process3.default.env.HTTP_PROXY || import_node_process3.default.env.http_proxy;
|
|
287
|
+
const httpsProxy = import_node_process3.default.env.HTTPS_PROXY || import_node_process3.default.env.https_proxy;
|
|
274
288
|
const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
|
|
275
289
|
const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
|
|
276
290
|
import_got_cjs.got.stream(dowmloadLink, {
|
|
@@ -282,7 +296,7 @@ async function download() {
|
|
|
282
296
|
logProgress(progress.percent);
|
|
283
297
|
}).pipe(file).on("finish", () => {
|
|
284
298
|
logProgressOver();
|
|
285
|
-
if (
|
|
299
|
+
if (import_node_process3.default.platform === "win32")
|
|
286
300
|
return resolve(caddyPath);
|
|
287
301
|
(0, import_node_fs.chmodSync)(caddyPath, 493);
|
|
288
302
|
resolve(caddyPath);
|
|
@@ -296,7 +310,7 @@ function testCaddy() {
|
|
|
296
310
|
if (!(0, import_node_fs.existsSync)(caddyPath))
|
|
297
311
|
return resolve(false);
|
|
298
312
|
(0, import_node_fs.chmodSync)(caddyPath, 493);
|
|
299
|
-
const child =
|
|
313
|
+
const child = import_node_process3.default.platform === "win32" ? (0, import_node_child_process2.spawn)(caddyPath, []) : (0, import_node_child_process2.spawn)("sudo", ["-E", caddyPath]);
|
|
300
314
|
child.on("close", () => {
|
|
301
315
|
return resolve(false);
|
|
302
316
|
});
|
|
@@ -327,15 +341,15 @@ var CaddyInstant = class {
|
|
|
327
341
|
this.host.add(ip, host);
|
|
328
342
|
await this.host.updateFinish();
|
|
329
343
|
return new Promise((resolve, reject) => {
|
|
330
|
-
if (
|
|
331
|
-
(0,
|
|
344
|
+
if (import_node_process3.default.platform === "win32") {
|
|
345
|
+
(0, import_node_child_process2.spawn)("ipconfig", ["/flushdns"]).on("error", (err) => {
|
|
332
346
|
consola.error(err);
|
|
333
347
|
return resolve(false);
|
|
334
348
|
}).on("close", () => {
|
|
335
349
|
resolve(true);
|
|
336
350
|
});
|
|
337
351
|
} else {
|
|
338
|
-
(0,
|
|
352
|
+
(0, import_node_child_process2.spawn)("sudo", ["-E", "killall", "-HUP", "mDNSResponder"]).on("error", (err) => {
|
|
339
353
|
consola.error(err);
|
|
340
354
|
return resolve(false);
|
|
341
355
|
}).on("close", () => {
|
|
@@ -349,15 +363,15 @@ var CaddyInstant = class {
|
|
|
349
363
|
this.host.remove(ip, host);
|
|
350
364
|
await this.host.updateFinish();
|
|
351
365
|
return new Promise((resolve, reject) => {
|
|
352
|
-
if (
|
|
353
|
-
(0,
|
|
366
|
+
if (import_node_process3.default.platform === "win32") {
|
|
367
|
+
(0, import_node_child_process2.spawn)("ipconfig", ["/flushdns"]).on("error", (err) => {
|
|
354
368
|
consola.error(err);
|
|
355
369
|
return resolve(false);
|
|
356
370
|
}).on("close", () => {
|
|
357
371
|
resolve(true);
|
|
358
372
|
});
|
|
359
373
|
} else {
|
|
360
|
-
(0,
|
|
374
|
+
(0, import_node_child_process2.spawn)("sudo", ["-E", "killall", "-HUP", "mDNSResponder"]).on("error", (err) => {
|
|
361
375
|
consola.error(err);
|
|
362
376
|
return resolve(false);
|
|
363
377
|
}).on("close", () => {
|
|
@@ -383,13 +397,13 @@ var CaddyInstant = class {
|
|
|
383
397
|
await this.init();
|
|
384
398
|
if (https && await tryPort(443))
|
|
385
399
|
await (0, import_kill_port.default)(443, "tcp");
|
|
386
|
-
if ((
|
|
400
|
+
if ((import_node_process3.default.platform === "win32" || !https) && await tryPort(80))
|
|
387
401
|
await (0, import_kill_port.default)(80, "tcp");
|
|
388
402
|
if (!await this.updateHost(source.split(":")[0], target.split(":")[0]))
|
|
389
403
|
throw new Error("update host failed");
|
|
390
404
|
consola.success("update host success\n");
|
|
391
405
|
return new Promise((resolve, reject) => {
|
|
392
|
-
const child =
|
|
406
|
+
const child = import_node_process3.default.platform !== "win32" ? (0, import_node_child_process2.spawn)("sudo", ["-E", caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}${https ? "" : ":80"}`, "--to", `${source}`, "--internal-certs", "--insecure", "--disable-redirects"]) : (0, import_node_child_process2.spawn)(caddyPath, ["reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
393
407
|
child.on("error", (err) => {
|
|
394
408
|
return reject(err);
|
|
395
409
|
});
|
|
@@ -432,30 +446,30 @@ var caddy;
|
|
|
432
446
|
var _stop;
|
|
433
447
|
var _servce;
|
|
434
448
|
function registerExit(clear) {
|
|
435
|
-
|
|
449
|
+
import_node_process4.default.on("beforeExit", async (_code) => {
|
|
436
450
|
await clear();
|
|
437
451
|
});
|
|
438
|
-
|
|
452
|
+
import_node_process4.default.on("uncaughtException", async (err) => {
|
|
439
453
|
console.error("An uncaught error occurred!", err.stack);
|
|
440
454
|
await clear();
|
|
441
|
-
|
|
442
|
-
|
|
455
|
+
import_node_process4.default.nextTick(() => {
|
|
456
|
+
import_node_process4.default.exit(1);
|
|
443
457
|
});
|
|
444
458
|
});
|
|
445
|
-
|
|
459
|
+
import_node_process4.default.on("unhandledRejection", async (reason, promise) => {
|
|
446
460
|
console.error("Unhandled Rejection at:", promise, "reason:", reason);
|
|
447
461
|
await clear();
|
|
448
|
-
|
|
449
|
-
|
|
462
|
+
import_node_process4.default.nextTick(() => {
|
|
463
|
+
import_node_process4.default.exit(1);
|
|
450
464
|
});
|
|
451
465
|
});
|
|
452
|
-
|
|
466
|
+
import_node_process4.default.once("SIGINT", async () => {
|
|
453
467
|
await clear();
|
|
454
|
-
|
|
468
|
+
import_node_process4.default.exit(0);
|
|
455
469
|
});
|
|
456
|
-
|
|
470
|
+
import_node_process4.default.once("SIGTERM", async () => {
|
|
457
471
|
await clear();
|
|
458
|
-
|
|
472
|
+
import_node_process4.default.exit(0);
|
|
459
473
|
});
|
|
460
474
|
}
|
|
461
475
|
var unpluginFactory = (options) => ({
|
|
@@ -480,6 +494,10 @@ var unpluginFactory = (options) => ({
|
|
|
480
494
|
});
|
|
481
495
|
},
|
|
482
496
|
configureServer(server) {
|
|
497
|
+
if (!isAdmin()) {
|
|
498
|
+
consola.warn("please run as administrator");
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
483
501
|
if (config.command === "build")
|
|
484
502
|
return;
|
|
485
503
|
const {
|
|
@@ -497,9 +515,10 @@ var unpluginFactory = (options) => ({
|
|
|
497
515
|
server.printUrls = () => {
|
|
498
516
|
var _a;
|
|
499
517
|
_printUrls();
|
|
500
|
-
const pwd =
|
|
518
|
+
const pwd = import_node_process4.default.cwd();
|
|
501
519
|
const vireCacheDir = `${pwd}/node_modules/.vite`;
|
|
502
|
-
(0, import_node_fs2.
|
|
520
|
+
if ((0, import_node_fs2.existsSync)(vireCacheDir))
|
|
521
|
+
(0, import_node_fs2.chmodSync)(vireCacheDir, 511);
|
|
503
522
|
let source = `localhost:${config.server.port}`;
|
|
504
523
|
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
505
524
|
if (url) {
|
|
@@ -527,6 +546,12 @@ var unpluginFactory = (options) => ({
|
|
|
527
546
|
}
|
|
528
547
|
},
|
|
529
548
|
webpack(compiler) {
|
|
549
|
+
if (!isAdmin()) {
|
|
550
|
+
consola.warn("please run as administrator");
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
if (import_node_process4.default.env.NODE_ENV !== "development")
|
|
554
|
+
return;
|
|
530
555
|
const {
|
|
531
556
|
enable = true,
|
|
532
557
|
target = ""
|
|
@@ -541,7 +566,7 @@ var unpluginFactory = (options) => ({
|
|
|
541
566
|
const devServer = __spreadValues(__spreadValues({
|
|
542
567
|
host: "localhost",
|
|
543
568
|
port: 8080
|
|
544
|
-
}, compiler.options.devServer),
|
|
569
|
+
}, compiler.options.devServer), import_node_process4.default.VUE_CLI_SERVICE.projectOptions.devServer);
|
|
545
570
|
const source = `${devServer.host}:${devServer.port}`;
|
|
546
571
|
if (caddy)
|
|
547
572
|
return;
|
|
@@ -553,7 +578,7 @@ var unpluginFactory = (options) => ({
|
|
|
553
578
|
});
|
|
554
579
|
} catch (e) {
|
|
555
580
|
consola.error(e);
|
|
556
|
-
|
|
581
|
+
import_node_process4.default.exit(1);
|
|
557
582
|
}
|
|
558
583
|
};
|
|
559
584
|
caddy = new CaddyInstant();
|
package/dist/webpack.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
webpack_default
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-CT3M7EPZ.js";
|
|
4
|
+
import "./chunk-NH3VM3RE.js";
|
|
5
|
+
import "./chunk-NNO3ZUSU.js";
|
|
6
6
|
export {
|
|
7
7
|
webpack_default as default
|
|
8
8
|
};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import process from 'node:process'
|
|
2
|
-
import { chmodSync } from 'node:fs'
|
|
2
|
+
import { chmodSync, existsSync } from 'node:fs'
|
|
3
3
|
import type { UnpluginFactory } from 'unplugin'
|
|
4
4
|
import { createUnplugin } from 'unplugin'
|
|
5
5
|
import type { ResolvedConfig, ViteDevServer } from 'vite'
|
|
6
6
|
import c from 'picocolors'
|
|
7
|
-
import { consola, once } from './utils'
|
|
7
|
+
import { consola, isAdmin, once } from './utils'
|
|
8
8
|
import type { Options } from './types'
|
|
9
9
|
import { CaddyInstant } from './caddy'
|
|
10
10
|
|
|
@@ -69,6 +69,11 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
69
69
|
})
|
|
70
70
|
},
|
|
71
71
|
configureServer(server) {
|
|
72
|
+
if (!isAdmin()) {
|
|
73
|
+
consola.warn('please run as administrator')
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
|
|
72
77
|
if (config.command === 'build')
|
|
73
78
|
return
|
|
74
79
|
|
|
@@ -92,7 +97,8 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
92
97
|
// fix `Error: EPERM: operation not permitted`
|
|
93
98
|
const pwd = process.cwd()
|
|
94
99
|
const vireCacheDir = `${pwd}/node_modules/.vite`
|
|
95
|
-
|
|
100
|
+
if (existsSync(vireCacheDir))
|
|
101
|
+
chmodSync(vireCacheDir, 0o777)
|
|
96
102
|
|
|
97
103
|
let source = `localhost:${config.server.port}`
|
|
98
104
|
const url = server.resolvedUrls?.local[0]
|
|
@@ -123,6 +129,14 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
123
129
|
},
|
|
124
130
|
},
|
|
125
131
|
webpack(compiler) {
|
|
132
|
+
if (!isAdmin()) {
|
|
133
|
+
consola.warn('please run as administrator')
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (process.env.NODE_ENV !== 'development')
|
|
138
|
+
return
|
|
139
|
+
|
|
126
140
|
const {
|
|
127
141
|
enable = true,
|
|
128
142
|
target = '',
|
package/src/utils.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import process from 'node:process'
|
|
2
|
+
import { execSync } from 'node:child_process'
|
|
1
3
|
import { createConsola } from 'consola'
|
|
2
4
|
|
|
3
5
|
export const consola = createConsola({
|
|
@@ -13,3 +15,18 @@ export function once<T extends (...args: any[]) => any>(fn: T): (...args: Parame
|
|
|
13
15
|
return fn(...args)
|
|
14
16
|
}
|
|
15
17
|
}
|
|
18
|
+
|
|
19
|
+
export function isAdmin() {
|
|
20
|
+
if (process.platform === 'win32') {
|
|
21
|
+
try {
|
|
22
|
+
execSync('net session', { stdio: 'ignore' })
|
|
23
|
+
return true
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return process.getuid && process.getuid() === 0
|
|
31
|
+
}
|
|
32
|
+
}
|