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
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__spreadValues,
|
|
3
|
+
chmodRecursive,
|
|
3
4
|
consola,
|
|
4
5
|
isAdmin
|
|
5
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-RUJE3YFB.js";
|
|
6
7
|
|
|
7
8
|
// src/index.ts
|
|
8
9
|
import process4 from "process";
|
|
9
|
-
import {
|
|
10
|
+
import { existsSync as existsSync2 } from "fs";
|
|
10
11
|
import { createUnplugin } from "unplugin";
|
|
11
12
|
import c from "picocolors";
|
|
12
13
|
|
|
@@ -39,7 +40,7 @@ async function syncHost() {
|
|
|
39
40
|
process.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
|
|
40
41
|
(error, stdout, stderr) => {
|
|
41
42
|
if (error) {
|
|
42
|
-
|
|
43
|
+
consola.error(`exec error: ${error}`);
|
|
43
44
|
return resolve(false);
|
|
44
45
|
}
|
|
45
46
|
return resolve(true);
|
|
@@ -52,6 +53,8 @@ async function addHost(ip, host) {
|
|
|
52
53
|
chmodSync(getPathOfSystemHostsPath(), 511);
|
|
53
54
|
hostInstance.add("127.0.0.1", "localhost");
|
|
54
55
|
hostInstance.add(ip, host);
|
|
56
|
+
if (ip === "localhost")
|
|
57
|
+
hostInstance.add("127.0.0.1", host);
|
|
55
58
|
await hostInstance.updateFinish();
|
|
56
59
|
return await syncHost();
|
|
57
60
|
}
|
|
@@ -388,7 +391,31 @@ var CaddyInstant = class {
|
|
|
388
391
|
// src/index.ts
|
|
389
392
|
var config;
|
|
390
393
|
var caddy;
|
|
391
|
-
var
|
|
394
|
+
var pwd = process4.cwd();
|
|
395
|
+
function vitePrintUrls(server, options, source, target, base = "/", _printUrls) {
|
|
396
|
+
_printUrls == null ? void 0 : _printUrls();
|
|
397
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
398
|
+
if (existsSync2(viteCacheDir))
|
|
399
|
+
chmodRecursive(viteCacheDir, 511);
|
|
400
|
+
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
401
|
+
if (existsSync2(nuxtCacheDir))
|
|
402
|
+
chmodRecursive(nuxtCacheDir, 511);
|
|
403
|
+
try {
|
|
404
|
+
if (caddy)
|
|
405
|
+
return;
|
|
406
|
+
caddy = new CaddyInstant();
|
|
407
|
+
caddy.run(source, target, __spreadValues({
|
|
408
|
+
base
|
|
409
|
+
}, options)).then(() => {
|
|
410
|
+
const colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
|
|
411
|
+
consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
412
|
+
}).catch((e) => {
|
|
413
|
+
throw e;
|
|
414
|
+
});
|
|
415
|
+
} catch (e) {
|
|
416
|
+
consola.error(e);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
392
419
|
var unpluginFactory = (options) => ({
|
|
393
420
|
name: "unplugin-https-reverse-proxy",
|
|
394
421
|
enforce: "pre",
|
|
@@ -397,6 +424,7 @@ var unpluginFactory = (options) => ({
|
|
|
397
424
|
config = _config;
|
|
398
425
|
},
|
|
399
426
|
configureServer(server) {
|
|
427
|
+
var _a;
|
|
400
428
|
if (!isAdmin()) {
|
|
401
429
|
consola.warn("please run as administrator");
|
|
402
430
|
return;
|
|
@@ -413,38 +441,15 @@ var unpluginFactory = (options) => ({
|
|
|
413
441
|
consola.fail("please provide target");
|
|
414
442
|
return;
|
|
415
443
|
}
|
|
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
|
-
};
|
|
444
|
+
const _printUrls = server.printUrls.bind(server);
|
|
445
|
+
let source = `localhost:${config.server.port || 5173}`;
|
|
446
|
+
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
447
|
+
if (url) {
|
|
448
|
+
const u = new URL(url);
|
|
449
|
+
source = u.host;
|
|
450
|
+
}
|
|
451
|
+
const base = server.config.base || "/";
|
|
452
|
+
server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
|
|
448
453
|
}
|
|
449
454
|
},
|
|
450
455
|
webpack(compiler) {
|
|
@@ -465,6 +470,9 @@ var unpluginFactory = (options) => ({
|
|
|
465
470
|
consola.fail("please provide target");
|
|
466
471
|
return;
|
|
467
472
|
}
|
|
473
|
+
const nuxtCacheDir = `${pwd}/node_modules/.cache`;
|
|
474
|
+
if (existsSync2(nuxtCacheDir))
|
|
475
|
+
chmodRecursive(nuxtCacheDir, 511);
|
|
468
476
|
try {
|
|
469
477
|
const devServer = __spreadValues(__spreadValues({
|
|
470
478
|
host: "localhost",
|
|
@@ -501,6 +509,7 @@ var unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
|
|
|
501
509
|
var src_default = unplugin;
|
|
502
510
|
|
|
503
511
|
export {
|
|
512
|
+
vitePrintUrls,
|
|
504
513
|
unpluginFactory,
|
|
505
514
|
unplugin,
|
|
506
515
|
src_default
|
|
@@ -17,11 +17,30 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
|
|
18
18
|
// src/utils.ts
|
|
19
19
|
import process from "process";
|
|
20
|
+
import path from "path";
|
|
21
|
+
import { chmod, readdir, stat } from "fs/promises";
|
|
20
22
|
import { execSync } from "child_process";
|
|
21
23
|
import { createConsola } from "consola";
|
|
22
24
|
var consola = createConsola({
|
|
23
25
|
level: 3
|
|
24
26
|
}).withTag("reverse-proxy");
|
|
27
|
+
async function chmodRecursive(_path, mode) {
|
|
28
|
+
await chmod(_path, mode);
|
|
29
|
+
if ((await stat(_path)).isDirectory()) {
|
|
30
|
+
const children = await readdir(_path);
|
|
31
|
+
for (const child of children)
|
|
32
|
+
await chmodRecursive(path.join(_path, child), mode);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function once(fn) {
|
|
36
|
+
let called = false;
|
|
37
|
+
return (...args) => {
|
|
38
|
+
if (called)
|
|
39
|
+
return;
|
|
40
|
+
called = true;
|
|
41
|
+
return fn(...args);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
25
44
|
function isAdmin() {
|
|
26
45
|
if (process.platform === "win32") {
|
|
27
46
|
try {
|
|
@@ -38,5 +57,7 @@ function isAdmin() {
|
|
|
38
57
|
export {
|
|
39
58
|
__spreadValues,
|
|
40
59
|
consola,
|
|
60
|
+
chmodRecursive,
|
|
61
|
+
once,
|
|
41
62
|
isAdmin
|
|
42
63
|
};
|
package/dist/esbuild.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/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);
|
|
@@ -56,11 +57,21 @@ var import_picocolors = __toESM(require("picocolors"), 1);
|
|
|
56
57
|
|
|
57
58
|
// src/utils.ts
|
|
58
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");
|
|
59
62
|
var import_node_child_process = require("child_process");
|
|
60
63
|
var import_consola = require("consola");
|
|
61
64
|
var consola = (0, import_consola.createConsola)({
|
|
62
65
|
level: 3
|
|
63
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
|
+
}
|
|
64
75
|
function isAdmin() {
|
|
65
76
|
if (import_node_process.default.platform === "win32") {
|
|
66
77
|
try {
|
|
@@ -103,7 +114,7 @@ async function syncHost() {
|
|
|
103
114
|
import_node_process2.default.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
|
|
104
115
|
(error, stdout, stderr) => {
|
|
105
116
|
if (error) {
|
|
106
|
-
|
|
117
|
+
consola.error(`exec error: ${error}`);
|
|
107
118
|
return resolve(false);
|
|
108
119
|
}
|
|
109
120
|
return resolve(true);
|
|
@@ -116,6 +127,8 @@ async function addHost(ip, host) {
|
|
|
116
127
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
117
128
|
hostInstance.add("127.0.0.1", "localhost");
|
|
118
129
|
hostInstance.add(ip, host);
|
|
130
|
+
if (ip === "localhost")
|
|
131
|
+
hostInstance.add("127.0.0.1", host);
|
|
119
132
|
await hostInstance.updateFinish();
|
|
120
133
|
return await syncHost();
|
|
121
134
|
}
|
|
@@ -130,11 +143,11 @@ async function removeHost(ip, host) {
|
|
|
130
143
|
}
|
|
131
144
|
|
|
132
145
|
// src/caddy/constants.ts
|
|
133
|
-
var
|
|
146
|
+
var import_node_path2 = require("path");
|
|
134
147
|
var import_node_process3 = __toESM(require("process"), 1);
|
|
135
148
|
var TEMP_DIR = import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp";
|
|
136
|
-
var caddyPath = (0,
|
|
137
|
-
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");
|
|
138
151
|
var supportList = [
|
|
139
152
|
{
|
|
140
153
|
platform: "dragonfly",
|
|
@@ -452,7 +465,31 @@ var CaddyInstant = class {
|
|
|
452
465
|
// src/index.ts
|
|
453
466
|
var config;
|
|
454
467
|
var caddy;
|
|
455
|
-
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
|
+
}
|
|
456
493
|
var unpluginFactory = (options) => ({
|
|
457
494
|
name: "unplugin-https-reverse-proxy",
|
|
458
495
|
enforce: "pre",
|
|
@@ -461,6 +498,7 @@ var unpluginFactory = (options) => ({
|
|
|
461
498
|
config = _config;
|
|
462
499
|
},
|
|
463
500
|
configureServer(server) {
|
|
501
|
+
var _a;
|
|
464
502
|
if (!isAdmin()) {
|
|
465
503
|
consola.warn("please run as administrator");
|
|
466
504
|
return;
|
|
@@ -477,38 +515,15 @@ var unpluginFactory = (options) => ({
|
|
|
477
515
|
consola.fail("please provide target");
|
|
478
516
|
return;
|
|
479
517
|
}
|
|
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
|
-
};
|
|
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);
|
|
512
527
|
}
|
|
513
528
|
},
|
|
514
529
|
webpack(compiler) {
|
|
@@ -529,6 +544,9 @@ var unpluginFactory = (options) => ({
|
|
|
529
544
|
consola.fail("please provide target");
|
|
530
545
|
return;
|
|
531
546
|
}
|
|
547
|
+
const nuxtCacheDir = `${pwd}/node_modules/.cache`;
|
|
548
|
+
if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
|
|
549
|
+
chmodRecursive(nuxtCacheDir, 511);
|
|
532
550
|
try {
|
|
533
551
|
const devServer = __spreadValues(__spreadValues({
|
|
534
552
|
host: "localhost",
|
|
@@ -566,6 +584,7 @@ var src_default = unplugin;
|
|
|
566
584
|
// Annotate the CommonJS export names for ESM import in node:
|
|
567
585
|
0 && (module.exports = {
|
|
568
586
|
unplugin,
|
|
569
|
-
unpluginFactory
|
|
587
|
+
unpluginFactory,
|
|
588
|
+
vitePrintUrls
|
|
570
589
|
});
|
|
571
590
|
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-N6ZBBGYD.js";
|
|
7
|
+
import "./chunk-RUJE3YFB.js";
|
|
7
8
|
export {
|
|
8
9
|
src_default as default,
|
|
9
10
|
unplugin,
|
|
10
|
-
unpluginFactory
|
|
11
|
+
unpluginFactory,
|
|
12
|
+
vitePrintUrls
|
|
11
13
|
};
|