unplugin-https-reverse-proxy 1.0.0-beta.0 → 1.0.0-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.
- package/dist/{chunk-KYMRDRAJ.js → chunk-DUCXH7CX.js} +40 -35
- package/dist/{chunk-3RTK3FSZ.js → chunk-NNO3ZUSU.js} +10 -0
- package/dist/{chunk-AXBUFN6T.js → chunk-QIKJQBZH.js} +1 -1
- package/dist/{chunk-MDJOTQRD.js → chunk-Y5ZVZOMP.js} +1 -1
- package/dist/esbuild.cjs +38 -34
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +42 -36
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +6 -4
- package/dist/nuxt.cjs +60 -34
- package/dist/nuxt.js +22 -4
- package/dist/rollup.cjs +38 -34
- package/dist/rollup.js +2 -2
- package/dist/utils.cjs +13 -2
- package/dist/utils.d.cts +2 -1
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +5 -3
- package/dist/vite.cjs +38 -34
- package/dist/vite.js +3 -3
- package/dist/webpack.cjs +38 -34
- package/dist/webpack.js +3 -3
- package/package.json +2 -1
- package/src/host/index.ts +4 -1
- package/src/index.ts +46 -35
- package/src/nuxt.ts +21 -1
- package/src/utils.ts +10 -0
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
__spreadValues,
|
|
3
3
|
consola,
|
|
4
4
|
isAdmin
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-NNO3ZUSU.js";
|
|
6
6
|
|
|
7
7
|
// src/index.ts
|
|
8
8
|
import process4 from "process";
|
|
@@ -39,7 +39,7 @@ async function syncHost() {
|
|
|
39
39
|
process.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
|
|
40
40
|
(error, stdout, stderr) => {
|
|
41
41
|
if (error) {
|
|
42
|
-
|
|
42
|
+
consola.error(`exec error: ${error}`);
|
|
43
43
|
return resolve(false);
|
|
44
44
|
}
|
|
45
45
|
return resolve(true);
|
|
@@ -52,6 +52,8 @@ async function addHost(ip, host) {
|
|
|
52
52
|
chmodSync(getPathOfSystemHostsPath(), 511);
|
|
53
53
|
hostInstance.add("127.0.0.1", "localhost");
|
|
54
54
|
hostInstance.add(ip, host);
|
|
55
|
+
if (ip === "localhost")
|
|
56
|
+
hostInstance.add("127.0.0.1", host);
|
|
55
57
|
await hostInstance.updateFinish();
|
|
56
58
|
return await syncHost();
|
|
57
59
|
}
|
|
@@ -388,7 +390,31 @@ var CaddyInstant = class {
|
|
|
388
390
|
// src/index.ts
|
|
389
391
|
var config;
|
|
390
392
|
var caddy;
|
|
391
|
-
|
|
393
|
+
function vitePrintUrls(server, options, source, target, base = "/", _printUrls) {
|
|
394
|
+
_printUrls == null ? void 0 : _printUrls();
|
|
395
|
+
const pwd = process4.cwd();
|
|
396
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
397
|
+
if (existsSync2(viteCacheDir))
|
|
398
|
+
chmodSync3(viteCacheDir, 511);
|
|
399
|
+
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
400
|
+
if (existsSync2(nuxtCacheDir))
|
|
401
|
+
chmodSync3(nuxtCacheDir, 511);
|
|
402
|
+
try {
|
|
403
|
+
if (caddy)
|
|
404
|
+
return;
|
|
405
|
+
caddy = new CaddyInstant();
|
|
406
|
+
caddy.run(source, target, __spreadValues({
|
|
407
|
+
base
|
|
408
|
+
}, options)).then(() => {
|
|
409
|
+
const colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
|
|
410
|
+
consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
411
|
+
}).catch((e) => {
|
|
412
|
+
throw e;
|
|
413
|
+
});
|
|
414
|
+
} catch (e) {
|
|
415
|
+
consola.error(e);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
392
418
|
var unpluginFactory = (options) => ({
|
|
393
419
|
name: "unplugin-https-reverse-proxy",
|
|
394
420
|
enforce: "pre",
|
|
@@ -397,6 +423,7 @@ var unpluginFactory = (options) => ({
|
|
|
397
423
|
config = _config;
|
|
398
424
|
},
|
|
399
425
|
configureServer(server) {
|
|
426
|
+
var _a;
|
|
400
427
|
if (!isAdmin()) {
|
|
401
428
|
consola.warn("please run as administrator");
|
|
402
429
|
return;
|
|
@@ -413,38 +440,15 @@ var unpluginFactory = (options) => ({
|
|
|
413
440
|
consola.fail("please provide target");
|
|
414
441
|
return;
|
|
415
442
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
let source = `localhost:${config.server.port}`;
|
|
426
|
-
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
427
|
-
if (url) {
|
|
428
|
-
const u = new URL(url);
|
|
429
|
-
source = u.host;
|
|
430
|
-
}
|
|
431
|
-
const base = server.config.base || "/";
|
|
432
|
-
try {
|
|
433
|
-
if (caddy)
|
|
434
|
-
return;
|
|
435
|
-
caddy = new CaddyInstant();
|
|
436
|
-
caddy.run(source, target, __spreadValues({
|
|
437
|
-
base
|
|
438
|
-
}, options)).then(() => {
|
|
439
|
-
const colorUrl = (url2) => c.green(url2.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
|
|
440
|
-
consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
441
|
-
}).catch((e) => {
|
|
442
|
-
throw e;
|
|
443
|
-
});
|
|
444
|
-
} catch (e) {
|
|
445
|
-
consola.error(e);
|
|
446
|
-
}
|
|
447
|
-
};
|
|
443
|
+
const _printUrls = server.printUrls.bind(server);
|
|
444
|
+
let source = `localhost:${config.server.port || 5173}`;
|
|
445
|
+
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
446
|
+
if (url) {
|
|
447
|
+
const u = new URL(url);
|
|
448
|
+
source = u.host;
|
|
449
|
+
}
|
|
450
|
+
const base = server.config.base || "/";
|
|
451
|
+
server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
|
|
448
452
|
}
|
|
449
453
|
},
|
|
450
454
|
webpack(compiler) {
|
|
@@ -501,6 +505,7 @@ var unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
|
|
|
501
505
|
var src_default = unplugin;
|
|
502
506
|
|
|
503
507
|
export {
|
|
508
|
+
vitePrintUrls,
|
|
504
509
|
unpluginFactory,
|
|
505
510
|
unplugin,
|
|
506
511
|
src_default
|
|
@@ -22,6 +22,15 @@ import { createConsola } from "consola";
|
|
|
22
22
|
var consola = createConsola({
|
|
23
23
|
level: 3
|
|
24
24
|
}).withTag("reverse-proxy");
|
|
25
|
+
function once(fn) {
|
|
26
|
+
let called = false;
|
|
27
|
+
return (...args) => {
|
|
28
|
+
if (called)
|
|
29
|
+
return;
|
|
30
|
+
called = true;
|
|
31
|
+
return fn(...args);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
25
34
|
function isAdmin() {
|
|
26
35
|
if (process.platform === "win32") {
|
|
27
36
|
try {
|
|
@@ -38,5 +47,6 @@ function isAdmin() {
|
|
|
38
47
|
export {
|
|
39
48
|
__spreadValues,
|
|
40
49
|
consola,
|
|
50
|
+
once,
|
|
41
51
|
isAdmin
|
|
42
52
|
};
|
package/dist/esbuild.cjs
CHANGED
|
@@ -104,7 +104,7 @@ async function syncHost() {
|
|
|
104
104
|
import_node_process2.default.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
|
|
105
105
|
(error, stdout, stderr) => {
|
|
106
106
|
if (error) {
|
|
107
|
-
|
|
107
|
+
consola.error(`exec error: ${error}`);
|
|
108
108
|
return resolve(false);
|
|
109
109
|
}
|
|
110
110
|
return resolve(true);
|
|
@@ -117,6 +117,8 @@ async function addHost(ip, host) {
|
|
|
117
117
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
118
118
|
hostInstance.add("127.0.0.1", "localhost");
|
|
119
119
|
hostInstance.add(ip, host);
|
|
120
|
+
if (ip === "localhost")
|
|
121
|
+
hostInstance.add("127.0.0.1", host);
|
|
120
122
|
await hostInstance.updateFinish();
|
|
121
123
|
return await syncHost();
|
|
122
124
|
}
|
|
@@ -453,7 +455,31 @@ var CaddyInstant = class {
|
|
|
453
455
|
// src/index.ts
|
|
454
456
|
var config;
|
|
455
457
|
var caddy;
|
|
456
|
-
|
|
458
|
+
function vitePrintUrls(server, options, source, target, base = "/", _printUrls) {
|
|
459
|
+
_printUrls == null ? void 0 : _printUrls();
|
|
460
|
+
const pwd = import_node_process5.default.cwd();
|
|
461
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
462
|
+
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
463
|
+
(0, import_node_fs3.chmodSync)(viteCacheDir, 511);
|
|
464
|
+
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
465
|
+
if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
|
|
466
|
+
(0, import_node_fs3.chmodSync)(nuxtCacheDir, 511);
|
|
467
|
+
try {
|
|
468
|
+
if (caddy)
|
|
469
|
+
return;
|
|
470
|
+
caddy = new CaddyInstant();
|
|
471
|
+
caddy.run(source, target, __spreadValues({
|
|
472
|
+
base
|
|
473
|
+
}, options)).then(() => {
|
|
474
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
475
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
476
|
+
}).catch((e) => {
|
|
477
|
+
throw e;
|
|
478
|
+
});
|
|
479
|
+
} catch (e) {
|
|
480
|
+
consola.error(e);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
457
483
|
var unpluginFactory = (options) => ({
|
|
458
484
|
name: "unplugin-https-reverse-proxy",
|
|
459
485
|
enforce: "pre",
|
|
@@ -462,6 +488,7 @@ var unpluginFactory = (options) => ({
|
|
|
462
488
|
config = _config;
|
|
463
489
|
},
|
|
464
490
|
configureServer(server) {
|
|
491
|
+
var _a;
|
|
465
492
|
if (!isAdmin()) {
|
|
466
493
|
consola.warn("please run as administrator");
|
|
467
494
|
return;
|
|
@@ -478,38 +505,15 @@ var unpluginFactory = (options) => ({
|
|
|
478
505
|
consola.fail("please provide target");
|
|
479
506
|
return;
|
|
480
507
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
let source = `localhost:${config.server.port}`;
|
|
491
|
-
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
492
|
-
if (url) {
|
|
493
|
-
const u = new URL(url);
|
|
494
|
-
source = u.host;
|
|
495
|
-
}
|
|
496
|
-
const base = server.config.base || "/";
|
|
497
|
-
try {
|
|
498
|
-
if (caddy)
|
|
499
|
-
return;
|
|
500
|
-
caddy = new CaddyInstant();
|
|
501
|
-
caddy.run(source, target, __spreadValues({
|
|
502
|
-
base
|
|
503
|
-
}, options)).then(() => {
|
|
504
|
-
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
505
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
506
|
-
}).catch((e) => {
|
|
507
|
-
throw e;
|
|
508
|
-
});
|
|
509
|
-
} catch (e) {
|
|
510
|
-
consola.error(e);
|
|
511
|
-
}
|
|
512
|
-
};
|
|
508
|
+
const _printUrls = server.printUrls.bind(server);
|
|
509
|
+
let source = `localhost:${config.server.port || 5173}`;
|
|
510
|
+
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
511
|
+
if (url) {
|
|
512
|
+
const u = new URL(url);
|
|
513
|
+
source = u.host;
|
|
514
|
+
}
|
|
515
|
+
const base = server.config.base || "/";
|
|
516
|
+
server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
|
|
513
517
|
}
|
|
514
518
|
},
|
|
515
519
|
webpack(compiler) {
|
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -46,7 +46,8 @@ var src_exports = {};
|
|
|
46
46
|
__export(src_exports, {
|
|
47
47
|
default: () => src_default,
|
|
48
48
|
unplugin: () => unplugin,
|
|
49
|
-
unpluginFactory: () => unpluginFactory
|
|
49
|
+
unpluginFactory: () => unpluginFactory,
|
|
50
|
+
vitePrintUrls: () => vitePrintUrls
|
|
50
51
|
});
|
|
51
52
|
module.exports = __toCommonJS(src_exports);
|
|
52
53
|
var import_node_process5 = __toESM(require("process"), 1);
|
|
@@ -103,7 +104,7 @@ async function syncHost() {
|
|
|
103
104
|
import_node_process2.default.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
|
|
104
105
|
(error, stdout, stderr) => {
|
|
105
106
|
if (error) {
|
|
106
|
-
|
|
107
|
+
consola.error(`exec error: ${error}`);
|
|
107
108
|
return resolve(false);
|
|
108
109
|
}
|
|
109
110
|
return resolve(true);
|
|
@@ -116,6 +117,8 @@ async function addHost(ip, host) {
|
|
|
116
117
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
117
118
|
hostInstance.add("127.0.0.1", "localhost");
|
|
118
119
|
hostInstance.add(ip, host);
|
|
120
|
+
if (ip === "localhost")
|
|
121
|
+
hostInstance.add("127.0.0.1", host);
|
|
119
122
|
await hostInstance.updateFinish();
|
|
120
123
|
return await syncHost();
|
|
121
124
|
}
|
|
@@ -452,7 +455,31 @@ var CaddyInstant = class {
|
|
|
452
455
|
// src/index.ts
|
|
453
456
|
var config;
|
|
454
457
|
var caddy;
|
|
455
|
-
|
|
458
|
+
function vitePrintUrls(server, options, source, target, base = "/", _printUrls) {
|
|
459
|
+
_printUrls == null ? void 0 : _printUrls();
|
|
460
|
+
const pwd = import_node_process5.default.cwd();
|
|
461
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
462
|
+
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
463
|
+
(0, import_node_fs3.chmodSync)(viteCacheDir, 511);
|
|
464
|
+
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
465
|
+
if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
|
|
466
|
+
(0, import_node_fs3.chmodSync)(nuxtCacheDir, 511);
|
|
467
|
+
try {
|
|
468
|
+
if (caddy)
|
|
469
|
+
return;
|
|
470
|
+
caddy = new CaddyInstant();
|
|
471
|
+
caddy.run(source, target, __spreadValues({
|
|
472
|
+
base
|
|
473
|
+
}, options)).then(() => {
|
|
474
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
475
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
476
|
+
}).catch((e) => {
|
|
477
|
+
throw e;
|
|
478
|
+
});
|
|
479
|
+
} catch (e) {
|
|
480
|
+
consola.error(e);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
456
483
|
var unpluginFactory = (options) => ({
|
|
457
484
|
name: "unplugin-https-reverse-proxy",
|
|
458
485
|
enforce: "pre",
|
|
@@ -461,6 +488,7 @@ var unpluginFactory = (options) => ({
|
|
|
461
488
|
config = _config;
|
|
462
489
|
},
|
|
463
490
|
configureServer(server) {
|
|
491
|
+
var _a;
|
|
464
492
|
if (!isAdmin()) {
|
|
465
493
|
consola.warn("please run as administrator");
|
|
466
494
|
return;
|
|
@@ -477,38 +505,15 @@ var unpluginFactory = (options) => ({
|
|
|
477
505
|
consola.fail("please provide target");
|
|
478
506
|
return;
|
|
479
507
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
let source = `localhost:${config.server.port}`;
|
|
490
|
-
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
491
|
-
if (url) {
|
|
492
|
-
const u = new URL(url);
|
|
493
|
-
source = u.host;
|
|
494
|
-
}
|
|
495
|
-
const base = server.config.base || "/";
|
|
496
|
-
try {
|
|
497
|
-
if (caddy)
|
|
498
|
-
return;
|
|
499
|
-
caddy = new CaddyInstant();
|
|
500
|
-
caddy.run(source, target, __spreadValues({
|
|
501
|
-
base
|
|
502
|
-
}, options)).then(() => {
|
|
503
|
-
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
504
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
505
|
-
}).catch((e) => {
|
|
506
|
-
throw e;
|
|
507
|
-
});
|
|
508
|
-
} catch (e) {
|
|
509
|
-
consola.error(e);
|
|
510
|
-
}
|
|
511
|
-
};
|
|
508
|
+
const _printUrls = server.printUrls.bind(server);
|
|
509
|
+
let source = `localhost:${config.server.port || 5173}`;
|
|
510
|
+
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
511
|
+
if (url) {
|
|
512
|
+
const u = new URL(url);
|
|
513
|
+
source = u.host;
|
|
514
|
+
}
|
|
515
|
+
const base = server.config.base || "/";
|
|
516
|
+
server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
|
|
512
517
|
}
|
|
513
518
|
},
|
|
514
519
|
webpack(compiler) {
|
|
@@ -566,6 +571,7 @@ var src_default = unplugin;
|
|
|
566
571
|
// Annotate the CommonJS export names for ESM import in node:
|
|
567
572
|
0 && (module.exports = {
|
|
568
573
|
unplugin,
|
|
569
|
-
unpluginFactory
|
|
574
|
+
unpluginFactory,
|
|
575
|
+
vitePrintUrls
|
|
570
576
|
});
|
|
571
577
|
exports.default = module.exports;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as _unplugin from 'unplugin';
|
|
2
2
|
import { UnpluginFactory } from 'unplugin';
|
|
3
|
+
import { ViteDevServer } from 'vite';
|
|
3
4
|
import { Options } from './types.cjs';
|
|
4
5
|
|
|
6
|
+
declare function vitePrintUrls(server: ViteDevServer, options: Options, source: string, target: string, base?: string, _printUrls?: () => void): void;
|
|
5
7
|
declare const unpluginFactory: UnpluginFactory<Options>;
|
|
6
8
|
declare const unplugin: _unplugin.UnpluginInstance<Options, boolean>;
|
|
7
9
|
|
|
8
|
-
export { unplugin as default, unplugin, unpluginFactory };
|
|
10
|
+
export { unplugin as default, unplugin, unpluginFactory, vitePrintUrls };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as _unplugin from 'unplugin';
|
|
2
2
|
import { UnpluginFactory } from 'unplugin';
|
|
3
|
+
import { ViteDevServer } from 'vite';
|
|
3
4
|
import { Options } from './types.js';
|
|
4
5
|
|
|
6
|
+
declare function vitePrintUrls(server: ViteDevServer, options: Options, source: string, target: string, base?: string, _printUrls?: () => void): void;
|
|
5
7
|
declare const unpluginFactory: UnpluginFactory<Options>;
|
|
6
8
|
declare const unplugin: _unplugin.UnpluginInstance<Options, boolean>;
|
|
7
9
|
|
|
8
|
-
export { unplugin as default, unplugin, unpluginFactory };
|
|
10
|
+
export { unplugin as default, unplugin, unpluginFactory, vitePrintUrls };
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
src_default,
|
|
3
3
|
unplugin,
|
|
4
|
-
unpluginFactory
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
unpluginFactory,
|
|
5
|
+
vitePrintUrls
|
|
6
|
+
} from "./chunk-DUCXH7CX.js";
|
|
7
|
+
import "./chunk-NNO3ZUSU.js";
|
|
7
8
|
export {
|
|
8
9
|
src_default as default,
|
|
9
10
|
unplugin,
|
|
10
|
-
unpluginFactory
|
|
11
|
+
unpluginFactory,
|
|
12
|
+
vitePrintUrls
|
|
11
13
|
};
|
package/dist/nuxt.cjs
CHANGED
|
@@ -65,6 +65,15 @@ var import_consola = require("consola");
|
|
|
65
65
|
var consola = (0, import_consola.createConsola)({
|
|
66
66
|
level: 3
|
|
67
67
|
}).withTag("reverse-proxy");
|
|
68
|
+
function once(fn) {
|
|
69
|
+
let called = false;
|
|
70
|
+
return (...args) => {
|
|
71
|
+
if (called)
|
|
72
|
+
return;
|
|
73
|
+
called = true;
|
|
74
|
+
return fn(...args);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
68
77
|
function isAdmin() {
|
|
69
78
|
if (import_node_process.default.platform === "win32") {
|
|
70
79
|
try {
|
|
@@ -107,7 +116,7 @@ async function syncHost() {
|
|
|
107
116
|
import_node_process2.default.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
|
|
108
117
|
(error, stdout, stderr) => {
|
|
109
118
|
if (error) {
|
|
110
|
-
|
|
119
|
+
consola.error(`exec error: ${error}`);
|
|
111
120
|
return resolve(false);
|
|
112
121
|
}
|
|
113
122
|
return resolve(true);
|
|
@@ -120,6 +129,8 @@ async function addHost(ip, host) {
|
|
|
120
129
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
121
130
|
hostInstance.add("127.0.0.1", "localhost");
|
|
122
131
|
hostInstance.add(ip, host);
|
|
132
|
+
if (ip === "localhost")
|
|
133
|
+
hostInstance.add("127.0.0.1", host);
|
|
123
134
|
await hostInstance.updateFinish();
|
|
124
135
|
return await syncHost();
|
|
125
136
|
}
|
|
@@ -456,7 +467,31 @@ var CaddyInstant = class {
|
|
|
456
467
|
// src/index.ts
|
|
457
468
|
var config;
|
|
458
469
|
var caddy;
|
|
459
|
-
|
|
470
|
+
function vitePrintUrls(server, options, source, target, base = "/", _printUrls) {
|
|
471
|
+
_printUrls == null ? void 0 : _printUrls();
|
|
472
|
+
const pwd = import_node_process5.default.cwd();
|
|
473
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
474
|
+
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
475
|
+
(0, import_node_fs3.chmodSync)(viteCacheDir, 511);
|
|
476
|
+
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
477
|
+
if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
|
|
478
|
+
(0, import_node_fs3.chmodSync)(nuxtCacheDir, 511);
|
|
479
|
+
try {
|
|
480
|
+
if (caddy)
|
|
481
|
+
return;
|
|
482
|
+
caddy = new CaddyInstant();
|
|
483
|
+
caddy.run(source, target, __spreadValues({
|
|
484
|
+
base
|
|
485
|
+
}, options)).then(() => {
|
|
486
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
487
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
488
|
+
}).catch((e) => {
|
|
489
|
+
throw e;
|
|
490
|
+
});
|
|
491
|
+
} catch (e) {
|
|
492
|
+
consola.error(e);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
460
495
|
var unpluginFactory = (options) => ({
|
|
461
496
|
name: "unplugin-https-reverse-proxy",
|
|
462
497
|
enforce: "pre",
|
|
@@ -465,6 +500,7 @@ var unpluginFactory = (options) => ({
|
|
|
465
500
|
config = _config;
|
|
466
501
|
},
|
|
467
502
|
configureServer(server) {
|
|
503
|
+
var _a;
|
|
468
504
|
if (!isAdmin()) {
|
|
469
505
|
consola.warn("please run as administrator");
|
|
470
506
|
return;
|
|
@@ -481,38 +517,15 @@ var unpluginFactory = (options) => ({
|
|
|
481
517
|
consola.fail("please provide target");
|
|
482
518
|
return;
|
|
483
519
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
let source = `localhost:${config.server.port}`;
|
|
494
|
-
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
495
|
-
if (url) {
|
|
496
|
-
const u = new URL(url);
|
|
497
|
-
source = u.host;
|
|
498
|
-
}
|
|
499
|
-
const base = server.config.base || "/";
|
|
500
|
-
try {
|
|
501
|
-
if (caddy)
|
|
502
|
-
return;
|
|
503
|
-
caddy = new CaddyInstant();
|
|
504
|
-
caddy.run(source, target, __spreadValues({
|
|
505
|
-
base
|
|
506
|
-
}, options)).then(() => {
|
|
507
|
-
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
508
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
509
|
-
}).catch((e) => {
|
|
510
|
-
throw e;
|
|
511
|
-
});
|
|
512
|
-
} catch (e) {
|
|
513
|
-
consola.error(e);
|
|
514
|
-
}
|
|
515
|
-
};
|
|
520
|
+
const _printUrls = server.printUrls.bind(server);
|
|
521
|
+
let source = `localhost:${config.server.port || 5173}`;
|
|
522
|
+
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
523
|
+
if (url) {
|
|
524
|
+
const u = new URL(url);
|
|
525
|
+
source = u.host;
|
|
526
|
+
}
|
|
527
|
+
const base = server.config.base || "/";
|
|
528
|
+
server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
|
|
516
529
|
}
|
|
517
530
|
},
|
|
518
531
|
webpack(compiler) {
|
|
@@ -583,6 +596,19 @@ var nuxt_default = (0, import_kit.defineNuxtModule)({
|
|
|
583
596
|
setup(options, _nuxt) {
|
|
584
597
|
(0, import_kit.addVitePlugin)(() => vite_default(options));
|
|
585
598
|
(0, import_kit.addWebpackPlugin)(() => webpack_default(options));
|
|
599
|
+
let url = "";
|
|
600
|
+
_nuxt.hook("listen", (_, listener) => {
|
|
601
|
+
url = listener.url;
|
|
602
|
+
});
|
|
603
|
+
_nuxt.hook("vite:serverCreated", once((server) => {
|
|
604
|
+
const source = new URL(url).host;
|
|
605
|
+
if (!options.target) {
|
|
606
|
+
consola.fail("please provide target");
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
const base = _nuxt.options.app.baseURL || "/";
|
|
610
|
+
vitePrintUrls(server, options, source, options.target, base);
|
|
611
|
+
}));
|
|
586
612
|
}
|
|
587
613
|
});
|
|
588
614
|
exports.default = module.exports;
|
package/dist/nuxt.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
vite_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-Y5ZVZOMP.js";
|
|
4
4
|
import {
|
|
5
5
|
webpack_default
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import
|
|
8
|
-
|
|
6
|
+
} from "./chunk-QIKJQBZH.js";
|
|
7
|
+
import {
|
|
8
|
+
vitePrintUrls
|
|
9
|
+
} from "./chunk-DUCXH7CX.js";
|
|
10
|
+
import {
|
|
11
|
+
consola,
|
|
12
|
+
once
|
|
13
|
+
} from "./chunk-NNO3ZUSU.js";
|
|
9
14
|
|
|
10
15
|
// src/nuxt.ts
|
|
11
16
|
import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
|
|
@@ -18,6 +23,19 @@ var nuxt_default = defineNuxtModule({
|
|
|
18
23
|
setup(options, _nuxt) {
|
|
19
24
|
addVitePlugin(() => vite_default(options));
|
|
20
25
|
addWebpackPlugin(() => webpack_default(options));
|
|
26
|
+
let url = "";
|
|
27
|
+
_nuxt.hook("listen", (_, listener) => {
|
|
28
|
+
url = listener.url;
|
|
29
|
+
});
|
|
30
|
+
_nuxt.hook("vite:serverCreated", once((server) => {
|
|
31
|
+
const source = new URL(url).host;
|
|
32
|
+
if (!options.target) {
|
|
33
|
+
consola.fail("please provide target");
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const base = _nuxt.options.app.baseURL || "/";
|
|
37
|
+
vitePrintUrls(server, options, source, options.target, base);
|
|
38
|
+
}));
|
|
21
39
|
}
|
|
22
40
|
});
|
|
23
41
|
export {
|
package/dist/rollup.cjs
CHANGED
|
@@ -104,7 +104,7 @@ async function syncHost() {
|
|
|
104
104
|
import_node_process2.default.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
|
|
105
105
|
(error, stdout, stderr) => {
|
|
106
106
|
if (error) {
|
|
107
|
-
|
|
107
|
+
consola.error(`exec error: ${error}`);
|
|
108
108
|
return resolve(false);
|
|
109
109
|
}
|
|
110
110
|
return resolve(true);
|
|
@@ -117,6 +117,8 @@ async function addHost(ip, host) {
|
|
|
117
117
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
118
118
|
hostInstance.add("127.0.0.1", "localhost");
|
|
119
119
|
hostInstance.add(ip, host);
|
|
120
|
+
if (ip === "localhost")
|
|
121
|
+
hostInstance.add("127.0.0.1", host);
|
|
120
122
|
await hostInstance.updateFinish();
|
|
121
123
|
return await syncHost();
|
|
122
124
|
}
|
|
@@ -453,7 +455,31 @@ var CaddyInstant = class {
|
|
|
453
455
|
// src/index.ts
|
|
454
456
|
var config;
|
|
455
457
|
var caddy;
|
|
456
|
-
|
|
458
|
+
function vitePrintUrls(server, options, source, target, base = "/", _printUrls) {
|
|
459
|
+
_printUrls == null ? void 0 : _printUrls();
|
|
460
|
+
const pwd = import_node_process5.default.cwd();
|
|
461
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
462
|
+
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
463
|
+
(0, import_node_fs3.chmodSync)(viteCacheDir, 511);
|
|
464
|
+
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
465
|
+
if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
|
|
466
|
+
(0, import_node_fs3.chmodSync)(nuxtCacheDir, 511);
|
|
467
|
+
try {
|
|
468
|
+
if (caddy)
|
|
469
|
+
return;
|
|
470
|
+
caddy = new CaddyInstant();
|
|
471
|
+
caddy.run(source, target, __spreadValues({
|
|
472
|
+
base
|
|
473
|
+
}, options)).then(() => {
|
|
474
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
475
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
476
|
+
}).catch((e) => {
|
|
477
|
+
throw e;
|
|
478
|
+
});
|
|
479
|
+
} catch (e) {
|
|
480
|
+
consola.error(e);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
457
483
|
var unpluginFactory = (options) => ({
|
|
458
484
|
name: "unplugin-https-reverse-proxy",
|
|
459
485
|
enforce: "pre",
|
|
@@ -462,6 +488,7 @@ var unpluginFactory = (options) => ({
|
|
|
462
488
|
config = _config;
|
|
463
489
|
},
|
|
464
490
|
configureServer(server) {
|
|
491
|
+
var _a;
|
|
465
492
|
if (!isAdmin()) {
|
|
466
493
|
consola.warn("please run as administrator");
|
|
467
494
|
return;
|
|
@@ -478,38 +505,15 @@ var unpluginFactory = (options) => ({
|
|
|
478
505
|
consola.fail("please provide target");
|
|
479
506
|
return;
|
|
480
507
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
let source = `localhost:${config.server.port}`;
|
|
491
|
-
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
492
|
-
if (url) {
|
|
493
|
-
const u = new URL(url);
|
|
494
|
-
source = u.host;
|
|
495
|
-
}
|
|
496
|
-
const base = server.config.base || "/";
|
|
497
|
-
try {
|
|
498
|
-
if (caddy)
|
|
499
|
-
return;
|
|
500
|
-
caddy = new CaddyInstant();
|
|
501
|
-
caddy.run(source, target, __spreadValues({
|
|
502
|
-
base
|
|
503
|
-
}, options)).then(() => {
|
|
504
|
-
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
505
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
506
|
-
}).catch((e) => {
|
|
507
|
-
throw e;
|
|
508
|
-
});
|
|
509
|
-
} catch (e) {
|
|
510
|
-
consola.error(e);
|
|
511
|
-
}
|
|
512
|
-
};
|
|
508
|
+
const _printUrls = server.printUrls.bind(server);
|
|
509
|
+
let source = `localhost:${config.server.port || 5173}`;
|
|
510
|
+
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
511
|
+
if (url) {
|
|
512
|
+
const u = new URL(url);
|
|
513
|
+
source = u.host;
|
|
514
|
+
}
|
|
515
|
+
const base = server.config.base || "/";
|
|
516
|
+
server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
|
|
513
517
|
}
|
|
514
518
|
},
|
|
515
519
|
webpack(compiler) {
|
package/dist/rollup.js
CHANGED
package/dist/utils.cjs
CHANGED
|
@@ -31,7 +31,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var utils_exports = {};
|
|
32
32
|
__export(utils_exports, {
|
|
33
33
|
consola: () => consola,
|
|
34
|
-
isAdmin: () => isAdmin
|
|
34
|
+
isAdmin: () => isAdmin,
|
|
35
|
+
once: () => once
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(utils_exports);
|
|
37
38
|
var import_node_process = __toESM(require("process"), 1);
|
|
@@ -40,6 +41,15 @@ var import_consola = require("consola");
|
|
|
40
41
|
var consola = (0, import_consola.createConsola)({
|
|
41
42
|
level: 3
|
|
42
43
|
}).withTag("reverse-proxy");
|
|
44
|
+
function once(fn) {
|
|
45
|
+
let called = false;
|
|
46
|
+
return (...args) => {
|
|
47
|
+
if (called)
|
|
48
|
+
return;
|
|
49
|
+
called = true;
|
|
50
|
+
return fn(...args);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
43
53
|
function isAdmin() {
|
|
44
54
|
if (import_node_process.default.platform === "win32") {
|
|
45
55
|
try {
|
|
@@ -55,6 +65,7 @@ function isAdmin() {
|
|
|
55
65
|
// Annotate the CommonJS export names for ESM import in node:
|
|
56
66
|
0 && (module.exports = {
|
|
57
67
|
consola,
|
|
58
|
-
isAdmin
|
|
68
|
+
isAdmin,
|
|
69
|
+
once
|
|
59
70
|
});
|
|
60
71
|
exports.default = module.exports;
|
package/dist/utils.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as consola_dist_core from 'consola/dist/core';
|
|
2
2
|
|
|
3
3
|
declare const consola: consola_dist_core.ConsolaInstance;
|
|
4
|
+
declare function once<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>;
|
|
4
5
|
declare function isAdmin(): boolean | undefined;
|
|
5
6
|
|
|
6
|
-
export { consola, isAdmin };
|
|
7
|
+
export { consola, isAdmin, once };
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as consola_dist_core from 'consola/dist/core';
|
|
2
2
|
|
|
3
3
|
declare const consola: consola_dist_core.ConsolaInstance;
|
|
4
|
+
declare function once<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>;
|
|
4
5
|
declare function isAdmin(): boolean | undefined;
|
|
5
6
|
|
|
6
|
-
export { consola, isAdmin };
|
|
7
|
+
export { consola, isAdmin, once };
|
package/dist/utils.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -104,7 +104,7 @@ async function syncHost() {
|
|
|
104
104
|
import_node_process2.default.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
|
|
105
105
|
(error, stdout, stderr) => {
|
|
106
106
|
if (error) {
|
|
107
|
-
|
|
107
|
+
consola.error(`exec error: ${error}`);
|
|
108
108
|
return resolve(false);
|
|
109
109
|
}
|
|
110
110
|
return resolve(true);
|
|
@@ -117,6 +117,8 @@ async function addHost(ip, host) {
|
|
|
117
117
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
118
118
|
hostInstance.add("127.0.0.1", "localhost");
|
|
119
119
|
hostInstance.add(ip, host);
|
|
120
|
+
if (ip === "localhost")
|
|
121
|
+
hostInstance.add("127.0.0.1", host);
|
|
120
122
|
await hostInstance.updateFinish();
|
|
121
123
|
return await syncHost();
|
|
122
124
|
}
|
|
@@ -453,7 +455,31 @@ var CaddyInstant = class {
|
|
|
453
455
|
// src/index.ts
|
|
454
456
|
var config;
|
|
455
457
|
var caddy;
|
|
456
|
-
|
|
458
|
+
function vitePrintUrls(server, options, source, target, base = "/", _printUrls) {
|
|
459
|
+
_printUrls == null ? void 0 : _printUrls();
|
|
460
|
+
const pwd = import_node_process5.default.cwd();
|
|
461
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
462
|
+
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
463
|
+
(0, import_node_fs3.chmodSync)(viteCacheDir, 511);
|
|
464
|
+
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
465
|
+
if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
|
|
466
|
+
(0, import_node_fs3.chmodSync)(nuxtCacheDir, 511);
|
|
467
|
+
try {
|
|
468
|
+
if (caddy)
|
|
469
|
+
return;
|
|
470
|
+
caddy = new CaddyInstant();
|
|
471
|
+
caddy.run(source, target, __spreadValues({
|
|
472
|
+
base
|
|
473
|
+
}, options)).then(() => {
|
|
474
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
475
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
476
|
+
}).catch((e) => {
|
|
477
|
+
throw e;
|
|
478
|
+
});
|
|
479
|
+
} catch (e) {
|
|
480
|
+
consola.error(e);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
457
483
|
var unpluginFactory = (options) => ({
|
|
458
484
|
name: "unplugin-https-reverse-proxy",
|
|
459
485
|
enforce: "pre",
|
|
@@ -462,6 +488,7 @@ var unpluginFactory = (options) => ({
|
|
|
462
488
|
config = _config;
|
|
463
489
|
},
|
|
464
490
|
configureServer(server) {
|
|
491
|
+
var _a;
|
|
465
492
|
if (!isAdmin()) {
|
|
466
493
|
consola.warn("please run as administrator");
|
|
467
494
|
return;
|
|
@@ -478,38 +505,15 @@ var unpluginFactory = (options) => ({
|
|
|
478
505
|
consola.fail("please provide target");
|
|
479
506
|
return;
|
|
480
507
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
let source = `localhost:${config.server.port}`;
|
|
491
|
-
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
492
|
-
if (url) {
|
|
493
|
-
const u = new URL(url);
|
|
494
|
-
source = u.host;
|
|
495
|
-
}
|
|
496
|
-
const base = server.config.base || "/";
|
|
497
|
-
try {
|
|
498
|
-
if (caddy)
|
|
499
|
-
return;
|
|
500
|
-
caddy = new CaddyInstant();
|
|
501
|
-
caddy.run(source, target, __spreadValues({
|
|
502
|
-
base
|
|
503
|
-
}, options)).then(() => {
|
|
504
|
-
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
505
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
506
|
-
}).catch((e) => {
|
|
507
|
-
throw e;
|
|
508
|
-
});
|
|
509
|
-
} catch (e) {
|
|
510
|
-
consola.error(e);
|
|
511
|
-
}
|
|
512
|
-
};
|
|
508
|
+
const _printUrls = server.printUrls.bind(server);
|
|
509
|
+
let source = `localhost:${config.server.port || 5173}`;
|
|
510
|
+
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
511
|
+
if (url) {
|
|
512
|
+
const u = new URL(url);
|
|
513
|
+
source = u.host;
|
|
514
|
+
}
|
|
515
|
+
const base = server.config.base || "/";
|
|
516
|
+
server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
|
|
513
517
|
}
|
|
514
518
|
},
|
|
515
519
|
webpack(compiler) {
|
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -104,7 +104,7 @@ async function syncHost() {
|
|
|
104
104
|
import_node_process2.default.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
|
|
105
105
|
(error, stdout, stderr) => {
|
|
106
106
|
if (error) {
|
|
107
|
-
|
|
107
|
+
consola.error(`exec error: ${error}`);
|
|
108
108
|
return resolve(false);
|
|
109
109
|
}
|
|
110
110
|
return resolve(true);
|
|
@@ -117,6 +117,8 @@ async function addHost(ip, host) {
|
|
|
117
117
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
118
118
|
hostInstance.add("127.0.0.1", "localhost");
|
|
119
119
|
hostInstance.add(ip, host);
|
|
120
|
+
if (ip === "localhost")
|
|
121
|
+
hostInstance.add("127.0.0.1", host);
|
|
120
122
|
await hostInstance.updateFinish();
|
|
121
123
|
return await syncHost();
|
|
122
124
|
}
|
|
@@ -453,7 +455,31 @@ var CaddyInstant = class {
|
|
|
453
455
|
// src/index.ts
|
|
454
456
|
var config;
|
|
455
457
|
var caddy;
|
|
456
|
-
|
|
458
|
+
function vitePrintUrls(server, options, source, target, base = "/", _printUrls) {
|
|
459
|
+
_printUrls == null ? void 0 : _printUrls();
|
|
460
|
+
const pwd = import_node_process5.default.cwd();
|
|
461
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
462
|
+
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
463
|
+
(0, import_node_fs3.chmodSync)(viteCacheDir, 511);
|
|
464
|
+
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
465
|
+
if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
|
|
466
|
+
(0, import_node_fs3.chmodSync)(nuxtCacheDir, 511);
|
|
467
|
+
try {
|
|
468
|
+
if (caddy)
|
|
469
|
+
return;
|
|
470
|
+
caddy = new CaddyInstant();
|
|
471
|
+
caddy.run(source, target, __spreadValues({
|
|
472
|
+
base
|
|
473
|
+
}, options)).then(() => {
|
|
474
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
475
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
476
|
+
}).catch((e) => {
|
|
477
|
+
throw e;
|
|
478
|
+
});
|
|
479
|
+
} catch (e) {
|
|
480
|
+
consola.error(e);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
457
483
|
var unpluginFactory = (options) => ({
|
|
458
484
|
name: "unplugin-https-reverse-proxy",
|
|
459
485
|
enforce: "pre",
|
|
@@ -462,6 +488,7 @@ var unpluginFactory = (options) => ({
|
|
|
462
488
|
config = _config;
|
|
463
489
|
},
|
|
464
490
|
configureServer(server) {
|
|
491
|
+
var _a;
|
|
465
492
|
if (!isAdmin()) {
|
|
466
493
|
consola.warn("please run as administrator");
|
|
467
494
|
return;
|
|
@@ -478,38 +505,15 @@ var unpluginFactory = (options) => ({
|
|
|
478
505
|
consola.fail("please provide target");
|
|
479
506
|
return;
|
|
480
507
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
let source = `localhost:${config.server.port}`;
|
|
491
|
-
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
492
|
-
if (url) {
|
|
493
|
-
const u = new URL(url);
|
|
494
|
-
source = u.host;
|
|
495
|
-
}
|
|
496
|
-
const base = server.config.base || "/";
|
|
497
|
-
try {
|
|
498
|
-
if (caddy)
|
|
499
|
-
return;
|
|
500
|
-
caddy = new CaddyInstant();
|
|
501
|
-
caddy.run(source, target, __spreadValues({
|
|
502
|
-
base
|
|
503
|
-
}, options)).then(() => {
|
|
504
|
-
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
505
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
506
|
-
}).catch((e) => {
|
|
507
|
-
throw e;
|
|
508
|
-
});
|
|
509
|
-
} catch (e) {
|
|
510
|
-
consola.error(e);
|
|
511
|
-
}
|
|
512
|
-
};
|
|
508
|
+
const _printUrls = server.printUrls.bind(server);
|
|
509
|
+
let source = `localhost:${config.server.port || 5173}`;
|
|
510
|
+
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
511
|
+
if (url) {
|
|
512
|
+
const u = new URL(url);
|
|
513
|
+
source = u.host;
|
|
514
|
+
}
|
|
515
|
+
const base = server.config.base || "/";
|
|
516
|
+
server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
|
|
513
517
|
}
|
|
514
518
|
},
|
|
515
519
|
webpack(compiler) {
|
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-QIKJQBZH.js";
|
|
4
|
+
import "./chunk-DUCXH7CX.js";
|
|
5
|
+
import "./chunk-NNO3ZUSU.js";
|
|
6
6
|
export {
|
|
7
7
|
webpack_default as default
|
|
8
8
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-https-reverse-proxy",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.1",
|
|
5
5
|
"packageManager": "pnpm@8.6.12",
|
|
6
6
|
"description": "",
|
|
7
7
|
"license": "MIT",
|
|
@@ -141,6 +141,7 @@
|
|
|
141
141
|
"build:fix": "esno scripts/postbuild.ts",
|
|
142
142
|
"lint": "eslint .",
|
|
143
143
|
"play": "npm -C examples/vite run dev",
|
|
144
|
+
"play:nuxt": "npm -C examples/nuxt run dev",
|
|
144
145
|
"play:vuecli": "npm -C examples/vuecli run serve",
|
|
145
146
|
"play:vuecli4": "npm -C examples/vuecli4 run serve",
|
|
146
147
|
"release": "bumpp",
|
package/src/host/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { chmodSync } from 'node:fs'
|
|
|
4
4
|
|
|
5
5
|
// @ts-expect-error no type
|
|
6
6
|
import _Hosts from 'hosts-so-easy'
|
|
7
|
+
import { consola } from '../utils'
|
|
7
8
|
|
|
8
9
|
const Hosts = _Hosts.default || _Hosts
|
|
9
10
|
|
|
@@ -26,7 +27,7 @@ async function syncHost() {
|
|
|
26
27
|
: 'sudo -E killall -HUP mDNSResponder',
|
|
27
28
|
(error, stdout, stderr) => {
|
|
28
29
|
if (error) {
|
|
29
|
-
|
|
30
|
+
consola.error(`exec error: ${error}`)
|
|
30
31
|
return resolve(false)
|
|
31
32
|
}
|
|
32
33
|
return resolve(true)
|
|
@@ -39,6 +40,8 @@ export async function addHost(ip: string, host: string) {
|
|
|
39
40
|
chmodSync(getPathOfSystemHostsPath(), 0o777)
|
|
40
41
|
hostInstance.add('127.0.0.1', 'localhost')
|
|
41
42
|
hostInstance.add(ip, host)
|
|
43
|
+
if (ip === 'localhost')
|
|
44
|
+
hostInstance.add('127.0.0.1', host)
|
|
42
45
|
await hostInstance.updateFinish()
|
|
43
46
|
return await syncHost()
|
|
44
47
|
}
|
package/src/index.ts
CHANGED
|
@@ -12,7 +12,43 @@ let config: ResolvedConfig
|
|
|
12
12
|
|
|
13
13
|
let caddy: CaddyInstant
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
export function vitePrintUrls(
|
|
16
|
+
server: ViteDevServer,
|
|
17
|
+
options: Options,
|
|
18
|
+
source: string,
|
|
19
|
+
target: string,
|
|
20
|
+
base: string = '/',
|
|
21
|
+
_printUrls?: () => void,
|
|
22
|
+
) {
|
|
23
|
+
_printUrls?.()
|
|
24
|
+
|
|
25
|
+
// fix `Error: EPERM: operation not permitted`
|
|
26
|
+
const pwd = process.cwd()
|
|
27
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`
|
|
28
|
+
if (existsSync(viteCacheDir))
|
|
29
|
+
chmodSync(viteCacheDir, 0o777)
|
|
30
|
+
const nuxtCacheDir = `${pwd}/.nuxt`
|
|
31
|
+
if (existsSync(nuxtCacheDir))
|
|
32
|
+
chmodSync(nuxtCacheDir, 0o777)
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
if (caddy)
|
|
36
|
+
return
|
|
37
|
+
caddy = new CaddyInstant()
|
|
38
|
+
caddy.run(source, target, {
|
|
39
|
+
base,
|
|
40
|
+
...options,
|
|
41
|
+
}).then(() => {
|
|
42
|
+
const colorUrl = (url: string) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`))
|
|
43
|
+
consola.success(` ${c.green('➜')} ${c.bold('run caddy reverse proxy success')}: ${colorUrl(`${options.https ? 'https' : 'http'}://${target}${base}`)}`)
|
|
44
|
+
}).catch((e) => {
|
|
45
|
+
throw e
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
consola.error(e)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
16
52
|
|
|
17
53
|
export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
18
54
|
name: 'unplugin-https-reverse-proxy',
|
|
@@ -41,43 +77,18 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
41
77
|
return
|
|
42
78
|
}
|
|
43
79
|
|
|
44
|
-
|
|
80
|
+
const _printUrls = server.printUrls.bind(server)
|
|
45
81
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
82
|
+
let source = `localhost:${config.server.port || 5173}`
|
|
83
|
+
const url = server.resolvedUrls?.local[0]
|
|
84
|
+
if (url) {
|
|
85
|
+
const u = new URL(url)
|
|
86
|
+
source = u.host
|
|
87
|
+
}
|
|
49
88
|
|
|
50
|
-
|
|
51
|
-
const pwd = process.cwd()
|
|
52
|
-
const vireCacheDir = `${pwd}/node_modules/.vite`
|
|
53
|
-
if (existsSync(vireCacheDir))
|
|
54
|
-
chmodSync(vireCacheDir, 0o777)
|
|
89
|
+
const base = server.config.base || '/'
|
|
55
90
|
|
|
56
|
-
|
|
57
|
-
const url = server.resolvedUrls?.local[0]
|
|
58
|
-
if (url) {
|
|
59
|
-
const u = new URL(url)
|
|
60
|
-
source = u.host
|
|
61
|
-
}
|
|
62
|
-
const base = server.config.base || '/'
|
|
63
|
-
try {
|
|
64
|
-
if (caddy)
|
|
65
|
-
return
|
|
66
|
-
caddy = new CaddyInstant()
|
|
67
|
-
caddy.run(source, target, {
|
|
68
|
-
base,
|
|
69
|
-
...options,
|
|
70
|
-
}).then(() => {
|
|
71
|
-
const colorUrl = (url: string) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`))
|
|
72
|
-
consola.success(` ${c.green('➜')} ${c.bold('run caddy reverse proxy success')}: ${colorUrl(`${options.https ? 'https' : 'http'}://${target}${base}`)}`)
|
|
73
|
-
}).catch((e) => {
|
|
74
|
-
throw e
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
catch (e) {
|
|
78
|
-
consola.error(e)
|
|
79
|
-
}
|
|
80
|
-
}
|
|
91
|
+
server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls)
|
|
81
92
|
},
|
|
82
93
|
},
|
|
83
94
|
webpack(compiler) {
|
package/src/nuxt.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from '@nuxt/kit'
|
|
2
|
+
import type { ViteDevServer } from 'vite'
|
|
2
3
|
import vite from './vite'
|
|
3
4
|
import webpack from './webpack'
|
|
4
5
|
import type { Options } from './types'
|
|
5
6
|
import '@nuxt/schema'
|
|
7
|
+
import { consola, once } from './utils'
|
|
8
|
+
import { vitePrintUrls } from '.'
|
|
6
9
|
|
|
7
10
|
export interface ModuleOptions extends Options {
|
|
8
11
|
|
|
@@ -17,6 +20,23 @@ export default defineNuxtModule<ModuleOptions>({
|
|
|
17
20
|
addVitePlugin(() => vite(options))
|
|
18
21
|
addWebpackPlugin(() => webpack(options))
|
|
19
22
|
|
|
20
|
-
//
|
|
23
|
+
// https://github.com/nuxt/cli/issues/220#issuecomment-1735394141
|
|
24
|
+
let url = ''
|
|
25
|
+
_nuxt.hook('listen', (_, listener) => {
|
|
26
|
+
url = listener.url
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
_nuxt.hook('vite:serverCreated', once((server: ViteDevServer) => {
|
|
30
|
+
const source = new URL(url).host
|
|
31
|
+
|
|
32
|
+
if (!options.target) {
|
|
33
|
+
consola.fail('please provide target')
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const base = _nuxt.options.app.baseURL || '/'
|
|
38
|
+
|
|
39
|
+
vitePrintUrls(server, options, source, options.target, base)
|
|
40
|
+
}))
|
|
21
41
|
},
|
|
22
42
|
})
|
package/src/utils.ts
CHANGED
|
@@ -6,6 +6,16 @@ export const consola = createConsola({
|
|
|
6
6
|
level: 3,
|
|
7
7
|
}).withTag('reverse-proxy')
|
|
8
8
|
|
|
9
|
+
export function once<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T> {
|
|
10
|
+
let called = false
|
|
11
|
+
return (...args: any[]) => {
|
|
12
|
+
if (called)
|
|
13
|
+
return
|
|
14
|
+
called = true
|
|
15
|
+
return fn(...args)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
9
19
|
export function isAdmin() {
|
|
10
20
|
if (process.platform === 'win32') {
|
|
11
21
|
try {
|