unplugin-https-reverse-proxy 1.0.0-beta.0 → 1.0.0-beta.2
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-MDJOTQRD.js → chunk-DDD5N75Y.js} +1 -1
- package/dist/{chunk-KYMRDRAJ.js → chunk-N6ZBBGYD.js} +45 -36
- package/dist/{chunk-3RTK3FSZ.js → chunk-RUJE3YFB.js} +21 -0
- package/dist/{chunk-AXBUFN6T.js → chunk-VGLXVBHU.js} +1 -1
- package/dist/esbuild.cjs +54 -37
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +58 -39
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +6 -4
- package/dist/nuxt.cjs +76 -37
- package/dist/nuxt.js +22 -4
- package/dist/rollup.cjs +54 -37
- package/dist/rollup.js +2 -2
- package/dist/utils.cjs +25 -2
- package/dist/utils.d.cts +3 -1
- package/dist/utils.d.ts +3 -1
- package/dist/utils.js +7 -3
- package/dist/vite.cjs +54 -37
- package/dist/vite.js +3 -3
- package/dist/webpack.cjs +54 -37
- package/dist/webpack.js +3 -3
- package/package.json +2 -1
- package/src/host/index.ts +4 -1
- package/src/index.ts +53 -37
- package/src/nuxt.ts +21 -1
- package/src/utils.ts +21 -0
package/dist/nuxt.cjs
CHANGED
|
@@ -60,11 +60,30 @@ var import_picocolors = __toESM(require("picocolors"), 1);
|
|
|
60
60
|
|
|
61
61
|
// src/utils.ts
|
|
62
62
|
var import_node_process = __toESM(require("process"), 1);
|
|
63
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
64
|
+
var import_promises = require("fs/promises");
|
|
63
65
|
var import_node_child_process = require("child_process");
|
|
64
66
|
var import_consola = require("consola");
|
|
65
67
|
var consola = (0, import_consola.createConsola)({
|
|
66
68
|
level: 3
|
|
67
69
|
}).withTag("reverse-proxy");
|
|
70
|
+
async function chmodRecursive(_path, mode) {
|
|
71
|
+
await (0, import_promises.chmod)(_path, mode);
|
|
72
|
+
if ((await (0, import_promises.stat)(_path)).isDirectory()) {
|
|
73
|
+
const children = await (0, import_promises.readdir)(_path);
|
|
74
|
+
for (const child of children)
|
|
75
|
+
await chmodRecursive(import_node_path.default.join(_path, child), mode);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function once(fn) {
|
|
79
|
+
let called = false;
|
|
80
|
+
return (...args) => {
|
|
81
|
+
if (called)
|
|
82
|
+
return;
|
|
83
|
+
called = true;
|
|
84
|
+
return fn(...args);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
68
87
|
function isAdmin() {
|
|
69
88
|
if (import_node_process.default.platform === "win32") {
|
|
70
89
|
try {
|
|
@@ -107,7 +126,7 @@ async function syncHost() {
|
|
|
107
126
|
import_node_process2.default.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
|
|
108
127
|
(error, stdout, stderr) => {
|
|
109
128
|
if (error) {
|
|
110
|
-
|
|
129
|
+
consola.error(`exec error: ${error}`);
|
|
111
130
|
return resolve(false);
|
|
112
131
|
}
|
|
113
132
|
return resolve(true);
|
|
@@ -120,6 +139,8 @@ async function addHost(ip, host) {
|
|
|
120
139
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
121
140
|
hostInstance.add("127.0.0.1", "localhost");
|
|
122
141
|
hostInstance.add(ip, host);
|
|
142
|
+
if (ip === "localhost")
|
|
143
|
+
hostInstance.add("127.0.0.1", host);
|
|
123
144
|
await hostInstance.updateFinish();
|
|
124
145
|
return await syncHost();
|
|
125
146
|
}
|
|
@@ -134,11 +155,11 @@ async function removeHost(ip, host) {
|
|
|
134
155
|
}
|
|
135
156
|
|
|
136
157
|
// src/caddy/constants.ts
|
|
137
|
-
var
|
|
158
|
+
var import_node_path2 = require("path");
|
|
138
159
|
var import_node_process3 = __toESM(require("process"), 1);
|
|
139
160
|
var TEMP_DIR = import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp";
|
|
140
|
-
var caddyPath = (0,
|
|
141
|
-
var caddyFilePath = (0,
|
|
161
|
+
var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
|
|
162
|
+
var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
|
|
142
163
|
var supportList = [
|
|
143
164
|
{
|
|
144
165
|
platform: "dragonfly",
|
|
@@ -456,7 +477,31 @@ var CaddyInstant = class {
|
|
|
456
477
|
// src/index.ts
|
|
457
478
|
var config;
|
|
458
479
|
var caddy;
|
|
459
|
-
var
|
|
480
|
+
var pwd = import_node_process5.default.cwd();
|
|
481
|
+
function vitePrintUrls(server, options, source, target, base = "/", _printUrls) {
|
|
482
|
+
_printUrls == null ? void 0 : _printUrls();
|
|
483
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
484
|
+
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
485
|
+
chmodRecursive(viteCacheDir, 511);
|
|
486
|
+
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
487
|
+
if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
|
|
488
|
+
chmodRecursive(nuxtCacheDir, 511);
|
|
489
|
+
try {
|
|
490
|
+
if (caddy)
|
|
491
|
+
return;
|
|
492
|
+
caddy = new CaddyInstant();
|
|
493
|
+
caddy.run(source, target, __spreadValues({
|
|
494
|
+
base
|
|
495
|
+
}, options)).then(() => {
|
|
496
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
497
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
498
|
+
}).catch((e) => {
|
|
499
|
+
throw e;
|
|
500
|
+
});
|
|
501
|
+
} catch (e) {
|
|
502
|
+
consola.error(e);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
460
505
|
var unpluginFactory = (options) => ({
|
|
461
506
|
name: "unplugin-https-reverse-proxy",
|
|
462
507
|
enforce: "pre",
|
|
@@ -465,6 +510,7 @@ var unpluginFactory = (options) => ({
|
|
|
465
510
|
config = _config;
|
|
466
511
|
},
|
|
467
512
|
configureServer(server) {
|
|
513
|
+
var _a;
|
|
468
514
|
if (!isAdmin()) {
|
|
469
515
|
consola.warn("please run as administrator");
|
|
470
516
|
return;
|
|
@@ -481,38 +527,15 @@ var unpluginFactory = (options) => ({
|
|
|
481
527
|
consola.fail("please provide target");
|
|
482
528
|
return;
|
|
483
529
|
}
|
|
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
|
-
};
|
|
530
|
+
const _printUrls = server.printUrls.bind(server);
|
|
531
|
+
let source = `localhost:${config.server.port || 5173}`;
|
|
532
|
+
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
533
|
+
if (url) {
|
|
534
|
+
const u = new URL(url);
|
|
535
|
+
source = u.host;
|
|
536
|
+
}
|
|
537
|
+
const base = server.config.base || "/";
|
|
538
|
+
server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
|
|
516
539
|
}
|
|
517
540
|
},
|
|
518
541
|
webpack(compiler) {
|
|
@@ -533,6 +556,9 @@ var unpluginFactory = (options) => ({
|
|
|
533
556
|
consola.fail("please provide target");
|
|
534
557
|
return;
|
|
535
558
|
}
|
|
559
|
+
const nuxtCacheDir = `${pwd}/node_modules/.cache`;
|
|
560
|
+
if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
|
|
561
|
+
chmodRecursive(nuxtCacheDir, 511);
|
|
536
562
|
try {
|
|
537
563
|
const devServer = __spreadValues(__spreadValues({
|
|
538
564
|
host: "localhost",
|
|
@@ -583,6 +609,19 @@ var nuxt_default = (0, import_kit.defineNuxtModule)({
|
|
|
583
609
|
setup(options, _nuxt) {
|
|
584
610
|
(0, import_kit.addVitePlugin)(() => vite_default(options));
|
|
585
611
|
(0, import_kit.addWebpackPlugin)(() => webpack_default(options));
|
|
612
|
+
let url = "";
|
|
613
|
+
_nuxt.hook("listen", (_, listener) => {
|
|
614
|
+
url = listener.url;
|
|
615
|
+
});
|
|
616
|
+
_nuxt.hook("vite:serverCreated", once((server) => {
|
|
617
|
+
const source = new URL(url).host;
|
|
618
|
+
if (!options.target) {
|
|
619
|
+
consola.fail("please provide target");
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
const base = _nuxt.options.app.baseURL || "/";
|
|
623
|
+
vitePrintUrls(server, options, source, options.target, base);
|
|
624
|
+
}));
|
|
586
625
|
}
|
|
587
626
|
});
|
|
588
627
|
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-DDD5N75Y.js";
|
|
4
4
|
import {
|
|
5
5
|
webpack_default
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import
|
|
8
|
-
|
|
6
|
+
} from "./chunk-VGLXVBHU.js";
|
|
7
|
+
import {
|
|
8
|
+
vitePrintUrls
|
|
9
|
+
} from "./chunk-N6ZBBGYD.js";
|
|
10
|
+
import {
|
|
11
|
+
consola,
|
|
12
|
+
once
|
|
13
|
+
} from "./chunk-RUJE3YFB.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
|
@@ -57,11 +57,21 @@ var import_picocolors = __toESM(require("picocolors"), 1);
|
|
|
57
57
|
|
|
58
58
|
// src/utils.ts
|
|
59
59
|
var import_node_process = __toESM(require("process"), 1);
|
|
60
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
61
|
+
var import_promises = require("fs/promises");
|
|
60
62
|
var import_node_child_process = require("child_process");
|
|
61
63
|
var import_consola = require("consola");
|
|
62
64
|
var consola = (0, import_consola.createConsola)({
|
|
63
65
|
level: 3
|
|
64
66
|
}).withTag("reverse-proxy");
|
|
67
|
+
async function chmodRecursive(_path, mode) {
|
|
68
|
+
await (0, import_promises.chmod)(_path, mode);
|
|
69
|
+
if ((await (0, import_promises.stat)(_path)).isDirectory()) {
|
|
70
|
+
const children = await (0, import_promises.readdir)(_path);
|
|
71
|
+
for (const child of children)
|
|
72
|
+
await chmodRecursive(import_node_path.default.join(_path, child), mode);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
65
75
|
function isAdmin() {
|
|
66
76
|
if (import_node_process.default.platform === "win32") {
|
|
67
77
|
try {
|
|
@@ -104,7 +114,7 @@ async function syncHost() {
|
|
|
104
114
|
import_node_process2.default.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
|
|
105
115
|
(error, stdout, stderr) => {
|
|
106
116
|
if (error) {
|
|
107
|
-
|
|
117
|
+
consola.error(`exec error: ${error}`);
|
|
108
118
|
return resolve(false);
|
|
109
119
|
}
|
|
110
120
|
return resolve(true);
|
|
@@ -117,6 +127,8 @@ async function addHost(ip, host) {
|
|
|
117
127
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
118
128
|
hostInstance.add("127.0.0.1", "localhost");
|
|
119
129
|
hostInstance.add(ip, host);
|
|
130
|
+
if (ip === "localhost")
|
|
131
|
+
hostInstance.add("127.0.0.1", host);
|
|
120
132
|
await hostInstance.updateFinish();
|
|
121
133
|
return await syncHost();
|
|
122
134
|
}
|
|
@@ -131,11 +143,11 @@ async function removeHost(ip, host) {
|
|
|
131
143
|
}
|
|
132
144
|
|
|
133
145
|
// src/caddy/constants.ts
|
|
134
|
-
var
|
|
146
|
+
var import_node_path2 = require("path");
|
|
135
147
|
var import_node_process3 = __toESM(require("process"), 1);
|
|
136
148
|
var TEMP_DIR = import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp";
|
|
137
|
-
var caddyPath = (0,
|
|
138
|
-
var caddyFilePath = (0,
|
|
149
|
+
var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
|
|
150
|
+
var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
|
|
139
151
|
var supportList = [
|
|
140
152
|
{
|
|
141
153
|
platform: "dragonfly",
|
|
@@ -453,7 +465,31 @@ var CaddyInstant = class {
|
|
|
453
465
|
// src/index.ts
|
|
454
466
|
var config;
|
|
455
467
|
var caddy;
|
|
456
|
-
var
|
|
468
|
+
var pwd = import_node_process5.default.cwd();
|
|
469
|
+
function vitePrintUrls(server, options, source, target, base = "/", _printUrls) {
|
|
470
|
+
_printUrls == null ? void 0 : _printUrls();
|
|
471
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
472
|
+
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
473
|
+
chmodRecursive(viteCacheDir, 511);
|
|
474
|
+
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
475
|
+
if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
|
|
476
|
+
chmodRecursive(nuxtCacheDir, 511);
|
|
477
|
+
try {
|
|
478
|
+
if (caddy)
|
|
479
|
+
return;
|
|
480
|
+
caddy = new CaddyInstant();
|
|
481
|
+
caddy.run(source, target, __spreadValues({
|
|
482
|
+
base
|
|
483
|
+
}, options)).then(() => {
|
|
484
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
485
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
486
|
+
}).catch((e) => {
|
|
487
|
+
throw e;
|
|
488
|
+
});
|
|
489
|
+
} catch (e) {
|
|
490
|
+
consola.error(e);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
457
493
|
var unpluginFactory = (options) => ({
|
|
458
494
|
name: "unplugin-https-reverse-proxy",
|
|
459
495
|
enforce: "pre",
|
|
@@ -462,6 +498,7 @@ var unpluginFactory = (options) => ({
|
|
|
462
498
|
config = _config;
|
|
463
499
|
},
|
|
464
500
|
configureServer(server) {
|
|
501
|
+
var _a;
|
|
465
502
|
if (!isAdmin()) {
|
|
466
503
|
consola.warn("please run as administrator");
|
|
467
504
|
return;
|
|
@@ -478,38 +515,15 @@ var unpluginFactory = (options) => ({
|
|
|
478
515
|
consola.fail("please provide target");
|
|
479
516
|
return;
|
|
480
517
|
}
|
|
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
|
-
};
|
|
518
|
+
const _printUrls = server.printUrls.bind(server);
|
|
519
|
+
let source = `localhost:${config.server.port || 5173}`;
|
|
520
|
+
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
521
|
+
if (url) {
|
|
522
|
+
const u = new URL(url);
|
|
523
|
+
source = u.host;
|
|
524
|
+
}
|
|
525
|
+
const base = server.config.base || "/";
|
|
526
|
+
server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
|
|
513
527
|
}
|
|
514
528
|
},
|
|
515
529
|
webpack(compiler) {
|
|
@@ -530,6 +544,9 @@ var unpluginFactory = (options) => ({
|
|
|
530
544
|
consola.fail("please provide target");
|
|
531
545
|
return;
|
|
532
546
|
}
|
|
547
|
+
const nuxtCacheDir = `${pwd}/node_modules/.cache`;
|
|
548
|
+
if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
|
|
549
|
+
chmodRecursive(nuxtCacheDir, 511);
|
|
533
550
|
try {
|
|
534
551
|
const devServer = __spreadValues(__spreadValues({
|
|
535
552
|
host: "localhost",
|
package/dist/rollup.js
CHANGED
package/dist/utils.cjs
CHANGED
|
@@ -30,16 +30,37 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/utils.ts
|
|
31
31
|
var utils_exports = {};
|
|
32
32
|
__export(utils_exports, {
|
|
33
|
+
chmodRecursive: () => chmodRecursive,
|
|
33
34
|
consola: () => consola,
|
|
34
|
-
isAdmin: () => isAdmin
|
|
35
|
+
isAdmin: () => isAdmin,
|
|
36
|
+
once: () => once
|
|
35
37
|
});
|
|
36
38
|
module.exports = __toCommonJS(utils_exports);
|
|
37
39
|
var import_node_process = __toESM(require("process"), 1);
|
|
40
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
41
|
+
var import_promises = require("fs/promises");
|
|
38
42
|
var import_node_child_process = require("child_process");
|
|
39
43
|
var import_consola = require("consola");
|
|
40
44
|
var consola = (0, import_consola.createConsola)({
|
|
41
45
|
level: 3
|
|
42
46
|
}).withTag("reverse-proxy");
|
|
47
|
+
async function chmodRecursive(_path, mode) {
|
|
48
|
+
await (0, import_promises.chmod)(_path, mode);
|
|
49
|
+
if ((await (0, import_promises.stat)(_path)).isDirectory()) {
|
|
50
|
+
const children = await (0, import_promises.readdir)(_path);
|
|
51
|
+
for (const child of children)
|
|
52
|
+
await chmodRecursive(import_node_path.default.join(_path, child), mode);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function once(fn) {
|
|
56
|
+
let called = false;
|
|
57
|
+
return (...args) => {
|
|
58
|
+
if (called)
|
|
59
|
+
return;
|
|
60
|
+
called = true;
|
|
61
|
+
return fn(...args);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
43
64
|
function isAdmin() {
|
|
44
65
|
if (import_node_process.default.platform === "win32") {
|
|
45
66
|
try {
|
|
@@ -54,7 +75,9 @@ function isAdmin() {
|
|
|
54
75
|
}
|
|
55
76
|
// Annotate the CommonJS export names for ESM import in node:
|
|
56
77
|
0 && (module.exports = {
|
|
78
|
+
chmodRecursive,
|
|
57
79
|
consola,
|
|
58
|
-
isAdmin
|
|
80
|
+
isAdmin,
|
|
81
|
+
once
|
|
59
82
|
});
|
|
60
83
|
exports.default = module.exports;
|
package/dist/utils.d.cts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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 chmodRecursive(_path: string, mode: number): Promise<void>;
|
|
5
|
+
declare function once<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>;
|
|
4
6
|
declare function isAdmin(): boolean | undefined;
|
|
5
7
|
|
|
6
|
-
export { consola, isAdmin };
|
|
8
|
+
export { chmodRecursive, consola, isAdmin, once };
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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 chmodRecursive(_path: string, mode: number): Promise<void>;
|
|
5
|
+
declare function once<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>;
|
|
4
6
|
declare function isAdmin(): boolean | undefined;
|
|
5
7
|
|
|
6
|
-
export { consola, isAdmin };
|
|
8
|
+
export { chmodRecursive, consola, isAdmin, once };
|
package/dist/utils.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -57,11 +57,21 @@ var import_picocolors = __toESM(require("picocolors"), 1);
|
|
|
57
57
|
|
|
58
58
|
// src/utils.ts
|
|
59
59
|
var import_node_process = __toESM(require("process"), 1);
|
|
60
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
61
|
+
var import_promises = require("fs/promises");
|
|
60
62
|
var import_node_child_process = require("child_process");
|
|
61
63
|
var import_consola = require("consola");
|
|
62
64
|
var consola = (0, import_consola.createConsola)({
|
|
63
65
|
level: 3
|
|
64
66
|
}).withTag("reverse-proxy");
|
|
67
|
+
async function chmodRecursive(_path, mode) {
|
|
68
|
+
await (0, import_promises.chmod)(_path, mode);
|
|
69
|
+
if ((await (0, import_promises.stat)(_path)).isDirectory()) {
|
|
70
|
+
const children = await (0, import_promises.readdir)(_path);
|
|
71
|
+
for (const child of children)
|
|
72
|
+
await chmodRecursive(import_node_path.default.join(_path, child), mode);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
65
75
|
function isAdmin() {
|
|
66
76
|
if (import_node_process.default.platform === "win32") {
|
|
67
77
|
try {
|
|
@@ -104,7 +114,7 @@ async function syncHost() {
|
|
|
104
114
|
import_node_process2.default.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
|
|
105
115
|
(error, stdout, stderr) => {
|
|
106
116
|
if (error) {
|
|
107
|
-
|
|
117
|
+
consola.error(`exec error: ${error}`);
|
|
108
118
|
return resolve(false);
|
|
109
119
|
}
|
|
110
120
|
return resolve(true);
|
|
@@ -117,6 +127,8 @@ async function addHost(ip, host) {
|
|
|
117
127
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
118
128
|
hostInstance.add("127.0.0.1", "localhost");
|
|
119
129
|
hostInstance.add(ip, host);
|
|
130
|
+
if (ip === "localhost")
|
|
131
|
+
hostInstance.add("127.0.0.1", host);
|
|
120
132
|
await hostInstance.updateFinish();
|
|
121
133
|
return await syncHost();
|
|
122
134
|
}
|
|
@@ -131,11 +143,11 @@ async function removeHost(ip, host) {
|
|
|
131
143
|
}
|
|
132
144
|
|
|
133
145
|
// src/caddy/constants.ts
|
|
134
|
-
var
|
|
146
|
+
var import_node_path2 = require("path");
|
|
135
147
|
var import_node_process3 = __toESM(require("process"), 1);
|
|
136
148
|
var TEMP_DIR = import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp";
|
|
137
|
-
var caddyPath = (0,
|
|
138
|
-
var caddyFilePath = (0,
|
|
149
|
+
var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
|
|
150
|
+
var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
|
|
139
151
|
var supportList = [
|
|
140
152
|
{
|
|
141
153
|
platform: "dragonfly",
|
|
@@ -453,7 +465,31 @@ var CaddyInstant = class {
|
|
|
453
465
|
// src/index.ts
|
|
454
466
|
var config;
|
|
455
467
|
var caddy;
|
|
456
|
-
var
|
|
468
|
+
var pwd = import_node_process5.default.cwd();
|
|
469
|
+
function vitePrintUrls(server, options, source, target, base = "/", _printUrls) {
|
|
470
|
+
_printUrls == null ? void 0 : _printUrls();
|
|
471
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
472
|
+
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
473
|
+
chmodRecursive(viteCacheDir, 511);
|
|
474
|
+
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
475
|
+
if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
|
|
476
|
+
chmodRecursive(nuxtCacheDir, 511);
|
|
477
|
+
try {
|
|
478
|
+
if (caddy)
|
|
479
|
+
return;
|
|
480
|
+
caddy = new CaddyInstant();
|
|
481
|
+
caddy.run(source, target, __spreadValues({
|
|
482
|
+
base
|
|
483
|
+
}, options)).then(() => {
|
|
484
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
485
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
486
|
+
}).catch((e) => {
|
|
487
|
+
throw e;
|
|
488
|
+
});
|
|
489
|
+
} catch (e) {
|
|
490
|
+
consola.error(e);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
457
493
|
var unpluginFactory = (options) => ({
|
|
458
494
|
name: "unplugin-https-reverse-proxy",
|
|
459
495
|
enforce: "pre",
|
|
@@ -462,6 +498,7 @@ var unpluginFactory = (options) => ({
|
|
|
462
498
|
config = _config;
|
|
463
499
|
},
|
|
464
500
|
configureServer(server) {
|
|
501
|
+
var _a;
|
|
465
502
|
if (!isAdmin()) {
|
|
466
503
|
consola.warn("please run as administrator");
|
|
467
504
|
return;
|
|
@@ -478,38 +515,15 @@ var unpluginFactory = (options) => ({
|
|
|
478
515
|
consola.fail("please provide target");
|
|
479
516
|
return;
|
|
480
517
|
}
|
|
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
|
-
};
|
|
518
|
+
const _printUrls = server.printUrls.bind(server);
|
|
519
|
+
let source = `localhost:${config.server.port || 5173}`;
|
|
520
|
+
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
521
|
+
if (url) {
|
|
522
|
+
const u = new URL(url);
|
|
523
|
+
source = u.host;
|
|
524
|
+
}
|
|
525
|
+
const base = server.config.base || "/";
|
|
526
|
+
server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
|
|
513
527
|
}
|
|
514
528
|
},
|
|
515
529
|
webpack(compiler) {
|
|
@@ -530,6 +544,9 @@ var unpluginFactory = (options) => ({
|
|
|
530
544
|
consola.fail("please provide target");
|
|
531
545
|
return;
|
|
532
546
|
}
|
|
547
|
+
const nuxtCacheDir = `${pwd}/node_modules/.cache`;
|
|
548
|
+
if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
|
|
549
|
+
chmodRecursive(nuxtCacheDir, 511);
|
|
533
550
|
try {
|
|
534
551
|
const devServer = __spreadValues(__spreadValues({
|
|
535
552
|
host: "localhost",
|
package/dist/vite.js
CHANGED