unplugin-https-reverse-proxy 1.0.0-beta.2 → 1.0.0-beta.4
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-N6ZBBGYD.js → chunk-GAKOA5LE.js} +8 -4
- package/dist/esbuild.cjs +15 -3
- package/dist/esbuild.js +1 -1
- package/dist/index.cjs +15 -3
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +24 -113
- package/dist/nuxt.js +23 -21
- package/dist/rollup.cjs +15 -3
- package/dist/rollup.js +1 -1
- package/dist/vite.cjs +15 -3
- package/dist/vite.js +6 -3
- package/dist/webpack.cjs +15 -3
- package/dist/webpack.js +6 -3
- package/package.json +1 -1
- package/src/caddy/index.ts +4 -0
- package/src/index.ts +6 -7
- package/src/nuxt.ts +24 -19
- package/dist/chunk-DDD5N75Y.js +0 -11
- package/dist/chunk-VGLXVBHU.js +0 -11
|
@@ -2,7 +2,8 @@ import {
|
|
|
2
2
|
__spreadValues,
|
|
3
3
|
chmodRecursive,
|
|
4
4
|
consola,
|
|
5
|
-
isAdmin
|
|
5
|
+
isAdmin,
|
|
6
|
+
once
|
|
6
7
|
} from "./chunk-RUJE3YFB.js";
|
|
7
8
|
|
|
8
9
|
// src/index.ts
|
|
@@ -353,6 +354,9 @@ var CaddyInstant = class {
|
|
|
353
354
|
});
|
|
354
355
|
const originalExit = process3.exit.bind(process3);
|
|
355
356
|
process3.exit = async (code) => {
|
|
357
|
+
const port = Number(source.split(":")[1]);
|
|
358
|
+
if (!Number.isNaN(port) && await tryPort(port))
|
|
359
|
+
await kill(port, "tcp");
|
|
356
360
|
if (!restore || this.stoped)
|
|
357
361
|
return originalExit(code);
|
|
358
362
|
try {
|
|
@@ -392,7 +396,7 @@ var CaddyInstant = class {
|
|
|
392
396
|
var config;
|
|
393
397
|
var caddy;
|
|
394
398
|
var pwd = process4.cwd();
|
|
395
|
-
|
|
399
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
396
400
|
_printUrls == null ? void 0 : _printUrls();
|
|
397
401
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
398
402
|
if (existsSync2(viteCacheDir))
|
|
@@ -415,7 +419,7 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
|
|
|
415
419
|
} catch (e) {
|
|
416
420
|
consola.error(e);
|
|
417
421
|
}
|
|
418
|
-
}
|
|
422
|
+
});
|
|
419
423
|
var unpluginFactory = (options) => ({
|
|
420
424
|
name: "unplugin-https-reverse-proxy",
|
|
421
425
|
enforce: "pre",
|
|
@@ -449,7 +453,7 @@ var unpluginFactory = (options) => ({
|
|
|
449
453
|
source = u.host;
|
|
450
454
|
}
|
|
451
455
|
const base = server.config.base || "/";
|
|
452
|
-
server.printUrls = () => vitePrintUrls(
|
|
456
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
|
|
453
457
|
}
|
|
454
458
|
},
|
|
455
459
|
webpack(compiler) {
|
package/dist/esbuild.cjs
CHANGED
|
@@ -72,6 +72,15 @@ async function chmodRecursive(_path, mode) {
|
|
|
72
72
|
await chmodRecursive(import_node_path.default.join(_path, child), mode);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
+
function once(fn) {
|
|
76
|
+
let called = false;
|
|
77
|
+
return (...args) => {
|
|
78
|
+
if (called)
|
|
79
|
+
return;
|
|
80
|
+
called = true;
|
|
81
|
+
return fn(...args);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
75
84
|
function isAdmin() {
|
|
76
85
|
if (import_node_process.default.platform === "win32") {
|
|
77
86
|
try {
|
|
@@ -427,6 +436,9 @@ var CaddyInstant = class {
|
|
|
427
436
|
});
|
|
428
437
|
const originalExit = import_node_process4.default.exit.bind(import_node_process4.default);
|
|
429
438
|
import_node_process4.default.exit = async (code) => {
|
|
439
|
+
const port = Number(source.split(":")[1]);
|
|
440
|
+
if (!Number.isNaN(port) && await tryPort(port))
|
|
441
|
+
await (0, import_kill_port.default)(port, "tcp");
|
|
430
442
|
if (!restore || this.stoped)
|
|
431
443
|
return originalExit(code);
|
|
432
444
|
try {
|
|
@@ -466,7 +478,7 @@ var CaddyInstant = class {
|
|
|
466
478
|
var config;
|
|
467
479
|
var caddy;
|
|
468
480
|
var pwd = import_node_process5.default.cwd();
|
|
469
|
-
|
|
481
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
470
482
|
_printUrls == null ? void 0 : _printUrls();
|
|
471
483
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
472
484
|
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
@@ -489,7 +501,7 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
|
|
|
489
501
|
} catch (e) {
|
|
490
502
|
consola.error(e);
|
|
491
503
|
}
|
|
492
|
-
}
|
|
504
|
+
});
|
|
493
505
|
var unpluginFactory = (options) => ({
|
|
494
506
|
name: "unplugin-https-reverse-proxy",
|
|
495
507
|
enforce: "pre",
|
|
@@ -523,7 +535,7 @@ var unpluginFactory = (options) => ({
|
|
|
523
535
|
source = u.host;
|
|
524
536
|
}
|
|
525
537
|
const base = server.config.base || "/";
|
|
526
|
-
server.printUrls = () => vitePrintUrls(
|
|
538
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
|
|
527
539
|
}
|
|
528
540
|
},
|
|
529
541
|
webpack(compiler) {
|
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -72,6 +72,15 @@ async function chmodRecursive(_path, mode) {
|
|
|
72
72
|
await chmodRecursive(import_node_path.default.join(_path, child), mode);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
+
function once(fn) {
|
|
76
|
+
let called = false;
|
|
77
|
+
return (...args) => {
|
|
78
|
+
if (called)
|
|
79
|
+
return;
|
|
80
|
+
called = true;
|
|
81
|
+
return fn(...args);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
75
84
|
function isAdmin() {
|
|
76
85
|
if (import_node_process.default.platform === "win32") {
|
|
77
86
|
try {
|
|
@@ -427,6 +436,9 @@ var CaddyInstant = class {
|
|
|
427
436
|
});
|
|
428
437
|
const originalExit = import_node_process4.default.exit.bind(import_node_process4.default);
|
|
429
438
|
import_node_process4.default.exit = async (code) => {
|
|
439
|
+
const port = Number(source.split(":")[1]);
|
|
440
|
+
if (!Number.isNaN(port) && await tryPort(port))
|
|
441
|
+
await (0, import_kill_port.default)(port, "tcp");
|
|
430
442
|
if (!restore || this.stoped)
|
|
431
443
|
return originalExit(code);
|
|
432
444
|
try {
|
|
@@ -466,7 +478,7 @@ var CaddyInstant = class {
|
|
|
466
478
|
var config;
|
|
467
479
|
var caddy;
|
|
468
480
|
var pwd = import_node_process5.default.cwd();
|
|
469
|
-
|
|
481
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
470
482
|
_printUrls == null ? void 0 : _printUrls();
|
|
471
483
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
472
484
|
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
@@ -489,7 +501,7 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
|
|
|
489
501
|
} catch (e) {
|
|
490
502
|
consola.error(e);
|
|
491
503
|
}
|
|
492
|
-
}
|
|
504
|
+
});
|
|
493
505
|
var unpluginFactory = (options) => ({
|
|
494
506
|
name: "unplugin-https-reverse-proxy",
|
|
495
507
|
enforce: "pre",
|
|
@@ -523,7 +535,7 @@ var unpluginFactory = (options) => ({
|
|
|
523
535
|
source = u.host;
|
|
524
536
|
}
|
|
525
537
|
const base = server.config.base || "/";
|
|
526
|
-
server.printUrls = () => vitePrintUrls(
|
|
538
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
|
|
527
539
|
}
|
|
528
540
|
},
|
|
529
541
|
webpack(compiler) {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as _unplugin from 'unplugin';
|
|
2
2
|
import { UnpluginFactory } from 'unplugin';
|
|
3
|
-
import { ViteDevServer } from 'vite';
|
|
4
3
|
import { Options } from './types.cjs';
|
|
5
4
|
|
|
6
|
-
declare
|
|
5
|
+
declare const vitePrintUrls: (options: Options, source: string, target: string, base?: string | undefined, _printUrls?: (() => void) | undefined) => void;
|
|
7
6
|
declare const unpluginFactory: UnpluginFactory<Options>;
|
|
8
7
|
declare const unplugin: _unplugin.UnpluginInstance<Options, boolean>;
|
|
9
8
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as _unplugin from 'unplugin';
|
|
2
2
|
import { UnpluginFactory } from 'unplugin';
|
|
3
|
-
import { ViteDevServer } from 'vite';
|
|
4
3
|
import { Options } from './types.js';
|
|
5
4
|
|
|
6
|
-
declare
|
|
5
|
+
declare const vitePrintUrls: (options: Options, source: string, target: string, base?: string | undefined, _printUrls?: (() => void) | undefined) => void;
|
|
7
6
|
declare const unpluginFactory: UnpluginFactory<Options>;
|
|
8
7
|
declare const unplugin: _unplugin.UnpluginInstance<Options, boolean>;
|
|
9
8
|
|
package/dist/index.js
CHANGED
package/dist/nuxt.cjs
CHANGED
|
@@ -47,16 +47,9 @@ __export(nuxt_exports, {
|
|
|
47
47
|
default: () => nuxt_default
|
|
48
48
|
});
|
|
49
49
|
module.exports = __toCommonJS(nuxt_exports);
|
|
50
|
+
var import_node_process6 = __toESM(require("process"), 1);
|
|
50
51
|
var import_kit = require("@nuxt/kit");
|
|
51
|
-
|
|
52
|
-
// src/vite.ts
|
|
53
|
-
var import_unplugin2 = require("unplugin");
|
|
54
|
-
|
|
55
|
-
// src/index.ts
|
|
56
|
-
var import_node_process5 = __toESM(require("process"), 1);
|
|
57
|
-
var import_node_fs3 = require("fs");
|
|
58
|
-
var import_unplugin = require("unplugin");
|
|
59
|
-
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
52
|
+
var import_schema = require("@nuxt/schema");
|
|
60
53
|
|
|
61
54
|
// src/utils.ts
|
|
62
55
|
var import_node_process = __toESM(require("process"), 1);
|
|
@@ -97,6 +90,12 @@ function isAdmin() {
|
|
|
97
90
|
}
|
|
98
91
|
}
|
|
99
92
|
|
|
93
|
+
// src/index.ts
|
|
94
|
+
var import_node_process5 = __toESM(require("process"), 1);
|
|
95
|
+
var import_node_fs3 = require("fs");
|
|
96
|
+
var import_unplugin = require("unplugin");
|
|
97
|
+
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
98
|
+
|
|
100
99
|
// src/caddy/index.ts
|
|
101
100
|
var import_node_os = require("os");
|
|
102
101
|
var import_node_process4 = __toESM(require("process"), 1);
|
|
@@ -439,6 +438,9 @@ var CaddyInstant = class {
|
|
|
439
438
|
});
|
|
440
439
|
const originalExit = import_node_process4.default.exit.bind(import_node_process4.default);
|
|
441
440
|
import_node_process4.default.exit = async (code) => {
|
|
441
|
+
const port = Number(source.split(":")[1]);
|
|
442
|
+
if (!Number.isNaN(port) && await tryPort(port))
|
|
443
|
+
await (0, import_kill_port.default)(port, "tcp");
|
|
442
444
|
if (!restore || this.stoped)
|
|
443
445
|
return originalExit(code);
|
|
444
446
|
try {
|
|
@@ -475,10 +477,9 @@ var CaddyInstant = class {
|
|
|
475
477
|
};
|
|
476
478
|
|
|
477
479
|
// src/index.ts
|
|
478
|
-
var config;
|
|
479
480
|
var caddy;
|
|
480
481
|
var pwd = import_node_process5.default.cwd();
|
|
481
|
-
|
|
482
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
482
483
|
_printUrls == null ? void 0 : _printUrls();
|
|
483
484
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
484
485
|
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
@@ -501,50 +502,20 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
|
|
|
501
502
|
} catch (e) {
|
|
502
503
|
consola.error(e);
|
|
503
504
|
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
},
|
|
512
|
-
configureServer(server) {
|
|
513
|
-
var _a;
|
|
514
|
-
if (!isAdmin()) {
|
|
515
|
-
consola.warn("please run as administrator");
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
|
-
if (config.command === "build")
|
|
519
|
-
return;
|
|
520
|
-
const {
|
|
521
|
-
enable = true,
|
|
522
|
-
target = ""
|
|
523
|
-
} = options;
|
|
524
|
-
if (!enable)
|
|
525
|
-
return;
|
|
526
|
-
if (!target) {
|
|
527
|
-
consola.fail("please provide target");
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
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);
|
|
539
|
-
}
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
// src/nuxt.ts
|
|
508
|
+
var nuxt_default = (0, import_kit.defineNuxtModule)({
|
|
509
|
+
meta: {
|
|
510
|
+
name: "nuxt-unplugin-https-reverse-proxy",
|
|
511
|
+
configKey: "unpluginHttpsReverseProxy"
|
|
540
512
|
},
|
|
541
|
-
|
|
542
|
-
var _a;
|
|
513
|
+
setup(options, _nuxt) {
|
|
543
514
|
if (!isAdmin()) {
|
|
544
515
|
consola.warn("please run as administrator");
|
|
545
516
|
return;
|
|
546
517
|
}
|
|
547
|
-
if (
|
|
518
|
+
if (import_node_process6.default.env.NODE_ENV !== "development")
|
|
548
519
|
return;
|
|
549
520
|
const {
|
|
550
521
|
enable = true,
|
|
@@ -556,72 +527,12 @@ var unpluginFactory = (options) => ({
|
|
|
556
527
|
consola.fail("please provide target");
|
|
557
528
|
return;
|
|
558
529
|
}
|
|
559
|
-
const nuxtCacheDir = `${pwd}/node_modules/.cache`;
|
|
560
|
-
if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
|
|
561
|
-
chmodRecursive(nuxtCacheDir, 511);
|
|
562
|
-
try {
|
|
563
|
-
const devServer = __spreadValues(__spreadValues({
|
|
564
|
-
host: "localhost",
|
|
565
|
-
port: 8080
|
|
566
|
-
}, compiler.options.devServer), import_node_process5.default.VUE_CLI_SERVICE.projectOptions.devServer);
|
|
567
|
-
const source = `${devServer.host}:${devServer.port}`;
|
|
568
|
-
if (caddy)
|
|
569
|
-
return;
|
|
570
|
-
const _close = (_a = compiler.close) == null ? void 0 : _a.bind(compiler);
|
|
571
|
-
if (_close) {
|
|
572
|
-
compiler.close = async (callback) => {
|
|
573
|
-
import_node_process5.default.on("exit", () => {
|
|
574
|
-
_close && _close(callback);
|
|
575
|
-
});
|
|
576
|
-
};
|
|
577
|
-
} else {
|
|
578
|
-
options.https = false;
|
|
579
|
-
}
|
|
580
|
-
caddy = new CaddyInstant();
|
|
581
|
-
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
582
|
-
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
583
|
-
compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
|
|
584
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
585
|
-
});
|
|
586
|
-
}).catch((e) => {
|
|
587
|
-
throw e;
|
|
588
|
-
});
|
|
589
|
-
} catch (e) {
|
|
590
|
-
consola.error(e);
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
});
|
|
594
|
-
|
|
595
|
-
// src/vite.ts
|
|
596
|
-
var vite_default = (0, import_unplugin2.createVitePlugin)(unpluginFactory);
|
|
597
|
-
|
|
598
|
-
// src/webpack.ts
|
|
599
|
-
var import_unplugin3 = require("unplugin");
|
|
600
|
-
var webpack_default = (0, import_unplugin3.createWebpackPlugin)(unpluginFactory);
|
|
601
|
-
|
|
602
|
-
// src/nuxt.ts
|
|
603
|
-
var import_schema = require("@nuxt/schema");
|
|
604
|
-
var nuxt_default = (0, import_kit.defineNuxtModule)({
|
|
605
|
-
meta: {
|
|
606
|
-
name: "nuxt-unplugin-https-reverse-proxy",
|
|
607
|
-
configKey: "unpluginHttpsReverseProxy"
|
|
608
|
-
},
|
|
609
|
-
setup(options, _nuxt) {
|
|
610
|
-
(0, import_kit.addVitePlugin)(() => vite_default(options));
|
|
611
|
-
(0, import_kit.addWebpackPlugin)(() => webpack_default(options));
|
|
612
|
-
let url = "";
|
|
613
530
|
_nuxt.hook("listen", (_, listener) => {
|
|
614
|
-
url = listener.url;
|
|
615
|
-
});
|
|
616
|
-
_nuxt.hook("vite:serverCreated", once((server) => {
|
|
531
|
+
const url = listener.url;
|
|
617
532
|
const source = new URL(url).host;
|
|
618
|
-
if (!options.target) {
|
|
619
|
-
consola.fail("please provide target");
|
|
620
|
-
return;
|
|
621
|
-
}
|
|
622
533
|
const base = _nuxt.options.app.baseURL || "/";
|
|
623
|
-
vitePrintUrls(
|
|
624
|
-
})
|
|
534
|
+
vitePrintUrls(options, source, options.target, base);
|
|
535
|
+
});
|
|
625
536
|
}
|
|
626
537
|
});
|
|
627
538
|
exports.default = module.exports;
|
package/dist/nuxt.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
vite_default
|
|
3
|
-
} from "./chunk-DDD5N75Y.js";
|
|
4
|
-
import {
|
|
5
|
-
webpack_default
|
|
6
|
-
} from "./chunk-VGLXVBHU.js";
|
|
7
1
|
import {
|
|
8
2
|
vitePrintUrls
|
|
9
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-GAKOA5LE.js";
|
|
10
4
|
import {
|
|
11
5
|
consola,
|
|
12
|
-
|
|
6
|
+
isAdmin
|
|
13
7
|
} from "./chunk-RUJE3YFB.js";
|
|
14
8
|
|
|
15
9
|
// src/nuxt.ts
|
|
16
|
-
import
|
|
10
|
+
import process from "process";
|
|
11
|
+
import { defineNuxtModule } from "@nuxt/kit";
|
|
17
12
|
import "@nuxt/schema";
|
|
18
13
|
var nuxt_default = defineNuxtModule({
|
|
19
14
|
meta: {
|
|
@@ -21,21 +16,28 @@ var nuxt_default = defineNuxtModule({
|
|
|
21
16
|
configKey: "unpluginHttpsReverseProxy"
|
|
22
17
|
},
|
|
23
18
|
setup(options, _nuxt) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
if (!isAdmin()) {
|
|
20
|
+
consola.warn("please run as administrator");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (process.env.NODE_ENV !== "development")
|
|
24
|
+
return;
|
|
25
|
+
const {
|
|
26
|
+
enable = true,
|
|
27
|
+
target = ""
|
|
28
|
+
} = options;
|
|
29
|
+
if (!enable)
|
|
30
|
+
return;
|
|
31
|
+
if (!target) {
|
|
32
|
+
consola.fail("please provide target");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
27
35
|
_nuxt.hook("listen", (_, listener) => {
|
|
28
|
-
url = listener.url;
|
|
29
|
-
});
|
|
30
|
-
_nuxt.hook("vite:serverCreated", once((server) => {
|
|
36
|
+
const url = listener.url;
|
|
31
37
|
const source = new URL(url).host;
|
|
32
|
-
if (!options.target) {
|
|
33
|
-
consola.fail("please provide target");
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
38
|
const base = _nuxt.options.app.baseURL || "/";
|
|
37
|
-
vitePrintUrls(
|
|
38
|
-
})
|
|
39
|
+
vitePrintUrls(options, source, options.target, base);
|
|
40
|
+
});
|
|
39
41
|
}
|
|
40
42
|
});
|
|
41
43
|
export {
|
package/dist/rollup.cjs
CHANGED
|
@@ -72,6 +72,15 @@ async function chmodRecursive(_path, mode) {
|
|
|
72
72
|
await chmodRecursive(import_node_path.default.join(_path, child), mode);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
+
function once(fn) {
|
|
76
|
+
let called = false;
|
|
77
|
+
return (...args) => {
|
|
78
|
+
if (called)
|
|
79
|
+
return;
|
|
80
|
+
called = true;
|
|
81
|
+
return fn(...args);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
75
84
|
function isAdmin() {
|
|
76
85
|
if (import_node_process.default.platform === "win32") {
|
|
77
86
|
try {
|
|
@@ -427,6 +436,9 @@ var CaddyInstant = class {
|
|
|
427
436
|
});
|
|
428
437
|
const originalExit = import_node_process4.default.exit.bind(import_node_process4.default);
|
|
429
438
|
import_node_process4.default.exit = async (code) => {
|
|
439
|
+
const port = Number(source.split(":")[1]);
|
|
440
|
+
if (!Number.isNaN(port) && await tryPort(port))
|
|
441
|
+
await (0, import_kill_port.default)(port, "tcp");
|
|
430
442
|
if (!restore || this.stoped)
|
|
431
443
|
return originalExit(code);
|
|
432
444
|
try {
|
|
@@ -466,7 +478,7 @@ var CaddyInstant = class {
|
|
|
466
478
|
var config;
|
|
467
479
|
var caddy;
|
|
468
480
|
var pwd = import_node_process5.default.cwd();
|
|
469
|
-
|
|
481
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
470
482
|
_printUrls == null ? void 0 : _printUrls();
|
|
471
483
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
472
484
|
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
@@ -489,7 +501,7 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
|
|
|
489
501
|
} catch (e) {
|
|
490
502
|
consola.error(e);
|
|
491
503
|
}
|
|
492
|
-
}
|
|
504
|
+
});
|
|
493
505
|
var unpluginFactory = (options) => ({
|
|
494
506
|
name: "unplugin-https-reverse-proxy",
|
|
495
507
|
enforce: "pre",
|
|
@@ -523,7 +535,7 @@ var unpluginFactory = (options) => ({
|
|
|
523
535
|
source = u.host;
|
|
524
536
|
}
|
|
525
537
|
const base = server.config.base || "/";
|
|
526
|
-
server.printUrls = () => vitePrintUrls(
|
|
538
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
|
|
527
539
|
}
|
|
528
540
|
},
|
|
529
541
|
webpack(compiler) {
|
package/dist/rollup.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -72,6 +72,15 @@ async function chmodRecursive(_path, mode) {
|
|
|
72
72
|
await chmodRecursive(import_node_path.default.join(_path, child), mode);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
+
function once(fn) {
|
|
76
|
+
let called = false;
|
|
77
|
+
return (...args) => {
|
|
78
|
+
if (called)
|
|
79
|
+
return;
|
|
80
|
+
called = true;
|
|
81
|
+
return fn(...args);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
75
84
|
function isAdmin() {
|
|
76
85
|
if (import_node_process.default.platform === "win32") {
|
|
77
86
|
try {
|
|
@@ -427,6 +436,9 @@ var CaddyInstant = class {
|
|
|
427
436
|
});
|
|
428
437
|
const originalExit = import_node_process4.default.exit.bind(import_node_process4.default);
|
|
429
438
|
import_node_process4.default.exit = async (code) => {
|
|
439
|
+
const port = Number(source.split(":")[1]);
|
|
440
|
+
if (!Number.isNaN(port) && await tryPort(port))
|
|
441
|
+
await (0, import_kill_port.default)(port, "tcp");
|
|
430
442
|
if (!restore || this.stoped)
|
|
431
443
|
return originalExit(code);
|
|
432
444
|
try {
|
|
@@ -466,7 +478,7 @@ var CaddyInstant = class {
|
|
|
466
478
|
var config;
|
|
467
479
|
var caddy;
|
|
468
480
|
var pwd = import_node_process5.default.cwd();
|
|
469
|
-
|
|
481
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
470
482
|
_printUrls == null ? void 0 : _printUrls();
|
|
471
483
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
472
484
|
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
@@ -489,7 +501,7 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
|
|
|
489
501
|
} catch (e) {
|
|
490
502
|
consola.error(e);
|
|
491
503
|
}
|
|
492
|
-
}
|
|
504
|
+
});
|
|
493
505
|
var unpluginFactory = (options) => ({
|
|
494
506
|
name: "unplugin-https-reverse-proxy",
|
|
495
507
|
enforce: "pre",
|
|
@@ -523,7 +535,7 @@ var unpluginFactory = (options) => ({
|
|
|
523
535
|
source = u.host;
|
|
524
536
|
}
|
|
525
537
|
const base = server.config.base || "/";
|
|
526
|
-
server.printUrls = () => vitePrintUrls(
|
|
538
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
|
|
527
539
|
}
|
|
528
540
|
},
|
|
529
541
|
webpack(compiler) {
|
package/dist/vite.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-N6ZBBGYD.js";
|
|
2
|
+
unpluginFactory
|
|
3
|
+
} from "./chunk-GAKOA5LE.js";
|
|
5
4
|
import "./chunk-RUJE3YFB.js";
|
|
5
|
+
|
|
6
|
+
// src/vite.ts
|
|
7
|
+
import { createVitePlugin } from "unplugin";
|
|
8
|
+
var vite_default = createVitePlugin(unpluginFactory);
|
|
6
9
|
export {
|
|
7
10
|
vite_default as default
|
|
8
11
|
};
|
package/dist/webpack.cjs
CHANGED
|
@@ -72,6 +72,15 @@ async function chmodRecursive(_path, mode) {
|
|
|
72
72
|
await chmodRecursive(import_node_path.default.join(_path, child), mode);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
+
function once(fn) {
|
|
76
|
+
let called = false;
|
|
77
|
+
return (...args) => {
|
|
78
|
+
if (called)
|
|
79
|
+
return;
|
|
80
|
+
called = true;
|
|
81
|
+
return fn(...args);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
75
84
|
function isAdmin() {
|
|
76
85
|
if (import_node_process.default.platform === "win32") {
|
|
77
86
|
try {
|
|
@@ -427,6 +436,9 @@ var CaddyInstant = class {
|
|
|
427
436
|
});
|
|
428
437
|
const originalExit = import_node_process4.default.exit.bind(import_node_process4.default);
|
|
429
438
|
import_node_process4.default.exit = async (code) => {
|
|
439
|
+
const port = Number(source.split(":")[1]);
|
|
440
|
+
if (!Number.isNaN(port) && await tryPort(port))
|
|
441
|
+
await (0, import_kill_port.default)(port, "tcp");
|
|
430
442
|
if (!restore || this.stoped)
|
|
431
443
|
return originalExit(code);
|
|
432
444
|
try {
|
|
@@ -466,7 +478,7 @@ var CaddyInstant = class {
|
|
|
466
478
|
var config;
|
|
467
479
|
var caddy;
|
|
468
480
|
var pwd = import_node_process5.default.cwd();
|
|
469
|
-
|
|
481
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
470
482
|
_printUrls == null ? void 0 : _printUrls();
|
|
471
483
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
472
484
|
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
@@ -489,7 +501,7 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
|
|
|
489
501
|
} catch (e) {
|
|
490
502
|
consola.error(e);
|
|
491
503
|
}
|
|
492
|
-
}
|
|
504
|
+
});
|
|
493
505
|
var unpluginFactory = (options) => ({
|
|
494
506
|
name: "unplugin-https-reverse-proxy",
|
|
495
507
|
enforce: "pre",
|
|
@@ -523,7 +535,7 @@ var unpluginFactory = (options) => ({
|
|
|
523
535
|
source = u.host;
|
|
524
536
|
}
|
|
525
537
|
const base = server.config.base || "/";
|
|
526
|
-
server.printUrls = () => vitePrintUrls(
|
|
538
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
|
|
527
539
|
}
|
|
528
540
|
},
|
|
529
541
|
webpack(compiler) {
|
package/dist/webpack.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-N6ZBBGYD.js";
|
|
2
|
+
unpluginFactory
|
|
3
|
+
} from "./chunk-GAKOA5LE.js";
|
|
5
4
|
import "./chunk-RUJE3YFB.js";
|
|
5
|
+
|
|
6
|
+
// src/webpack.ts
|
|
7
|
+
import { createWebpackPlugin } from "unplugin";
|
|
8
|
+
var webpack_default = createWebpackPlugin(unpluginFactory);
|
|
6
9
|
export {
|
|
7
10
|
webpack_default as default
|
|
8
11
|
};
|
package/package.json
CHANGED
package/src/caddy/index.ts
CHANGED
|
@@ -166,6 +166,10 @@ export class CaddyInstant {
|
|
|
166
166
|
|
|
167
167
|
// @ts-expect-error override
|
|
168
168
|
process.exit = async (code?: number) => {
|
|
169
|
+
const port = Number(source.split(':')[1])
|
|
170
|
+
if (!Number.isNaN(port) && await tryPort(port))
|
|
171
|
+
await kill(port, 'tcp')
|
|
172
|
+
|
|
169
173
|
if (!restore || this.stoped)
|
|
170
174
|
return originalExit(code)
|
|
171
175
|
|
package/src/index.ts
CHANGED
|
@@ -2,9 +2,9 @@ import process from 'node:process'
|
|
|
2
2
|
import { existsSync } from 'node:fs'
|
|
3
3
|
import type { UnpluginFactory } from 'unplugin'
|
|
4
4
|
import { createUnplugin } from 'unplugin'
|
|
5
|
-
import type { ResolvedConfig
|
|
5
|
+
import type { ResolvedConfig } from 'vite'
|
|
6
6
|
import c from 'picocolors'
|
|
7
|
-
import { chmodRecursive, consola, isAdmin } from './utils'
|
|
7
|
+
import { chmodRecursive, consola, isAdmin, once } from './utils'
|
|
8
8
|
import type { Options } from './types'
|
|
9
9
|
import { CaddyInstant } from './caddy'
|
|
10
10
|
|
|
@@ -14,14 +14,13 @@ let caddy: CaddyInstant
|
|
|
14
14
|
|
|
15
15
|
const pwd = process.cwd()
|
|
16
16
|
|
|
17
|
-
export
|
|
18
|
-
server: ViteDevServer,
|
|
17
|
+
export const vitePrintUrls = once((
|
|
19
18
|
options: Options,
|
|
20
19
|
source: string,
|
|
21
20
|
target: string,
|
|
22
21
|
base: string = '/',
|
|
23
22
|
_printUrls?: () => void,
|
|
24
|
-
) {
|
|
23
|
+
) => {
|
|
25
24
|
_printUrls?.()
|
|
26
25
|
|
|
27
26
|
// fix `Error: EPERM: operation not permitted`
|
|
@@ -49,7 +48,7 @@ export function vitePrintUrls(
|
|
|
49
48
|
catch (e) {
|
|
50
49
|
consola.error(e)
|
|
51
50
|
}
|
|
52
|
-
}
|
|
51
|
+
})
|
|
53
52
|
|
|
54
53
|
export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
55
54
|
name: 'unplugin-https-reverse-proxy',
|
|
@@ -89,7 +88,7 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
89
88
|
|
|
90
89
|
const base = server.config.base || '/'
|
|
91
90
|
|
|
92
|
-
server.printUrls = () => vitePrintUrls(
|
|
91
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls)
|
|
93
92
|
},
|
|
94
93
|
},
|
|
95
94
|
webpack(compiler) {
|
package/src/nuxt.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import vite from './vite'
|
|
4
|
-
import webpack from './webpack'
|
|
1
|
+
import process from 'node:process'
|
|
2
|
+
import { defineNuxtModule } from '@nuxt/kit'
|
|
5
3
|
import type { Options } from './types'
|
|
6
4
|
import '@nuxt/schema'
|
|
7
|
-
import { consola,
|
|
5
|
+
import { consola, isAdmin } from './utils'
|
|
8
6
|
import { vitePrintUrls } from '.'
|
|
9
7
|
|
|
10
8
|
export interface ModuleOptions extends Options {
|
|
@@ -17,26 +15,33 @@ export default defineNuxtModule<ModuleOptions>({
|
|
|
17
15
|
configKey: 'unpluginHttpsReverseProxy',
|
|
18
16
|
},
|
|
19
17
|
setup(options, _nuxt) {
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
if (!isAdmin()) {
|
|
19
|
+
consola.warn('please run as administrator')
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (process.env.NODE_ENV !== 'development')
|
|
24
|
+
return
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
enable = true,
|
|
28
|
+
target = '',
|
|
29
|
+
} = options
|
|
30
|
+
if (!enable)
|
|
31
|
+
return
|
|
32
|
+
if (!target) {
|
|
33
|
+
consola.fail('please provide target')
|
|
34
|
+
return
|
|
35
|
+
}
|
|
22
36
|
|
|
23
37
|
// https://github.com/nuxt/cli/issues/220#issuecomment-1735394141
|
|
24
|
-
let url = ''
|
|
25
38
|
_nuxt.hook('listen', (_, listener) => {
|
|
26
|
-
url = listener.url
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
_nuxt.hook('vite:serverCreated', once((server: ViteDevServer) => {
|
|
39
|
+
const url = listener.url
|
|
30
40
|
const source = new URL(url).host
|
|
31
41
|
|
|
32
|
-
if (!options.target) {
|
|
33
|
-
consola.fail('please provide target')
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
|
|
37
42
|
const base = _nuxt.options.app.baseURL || '/'
|
|
38
43
|
|
|
39
|
-
vitePrintUrls(
|
|
40
|
-
})
|
|
44
|
+
vitePrintUrls(options, source, options.target, base)
|
|
45
|
+
})
|
|
41
46
|
},
|
|
42
47
|
})
|
package/dist/chunk-DDD5N75Y.js
DELETED
package/dist/chunk-VGLXVBHU.js
DELETED