unplugin-https-reverse-proxy 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/chunk-3HKPYCSE.js +9 -0
- package/dist/{chunk-BWNBY4RY.js → chunk-H5P77DDT.js} +17 -12
- package/dist/{chunk-CCEFFLWU.js → chunk-HSJJYR6E.js} +1 -1
- package/dist/{chunk-YJTJH7KX.js → chunk-JN5C2QIT.js} +1 -1
- package/dist/esbuild.cjs +19 -12
- package/dist/esbuild.js +2 -1
- package/dist/index.cjs +19 -12
- package/dist/index.js +2 -1
- package/dist/nuxt.cjs +19 -12
- package/dist/nuxt.js +4 -3
- package/dist/rollup.cjs +19 -12
- package/dist/rollup.js +2 -1
- package/dist/utils.cjs +34 -0
- package/dist/utils.d.cts +5 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +6 -0
- package/dist/vite.cjs +19 -12
- package/dist/vite.js +3 -2
- package/dist/webpack.cjs +19 -12
- package/dist/webpack.js +3 -2
- package/package.json +3 -1
- package/scripts/postinstall.ts +16 -0
- package/src/caddy/index.ts +9 -10
- package/src/caddy/utils.ts +0 -1
- package/src/index.ts +9 -10
- package/src/utils.ts +5 -0
package/README.md
CHANGED
|
@@ -10,6 +10,12 @@ A plugin for https reverse proxy, support `vite` and `webpack`.
|
|
|
10
10
|
npm i unplugin-https-reverse-proxy
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
```ts
|
|
14
|
+
interface Options {
|
|
15
|
+
target: string // <- https target hostname
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
13
19
|
<details>
|
|
14
20
|
<summary>Vite</summary><br>
|
|
15
21
|
|
|
@@ -40,6 +46,7 @@ module.exports = {
|
|
|
40
46
|
// ↓ for HMR
|
|
41
47
|
webSocketURL: {
|
|
42
48
|
protocol: 'wss',
|
|
49
|
+
hostname: 'xxx', // <- target hostname
|
|
43
50
|
port: 443,
|
|
44
51
|
},
|
|
45
52
|
},
|
|
@@ -79,6 +86,7 @@ module.exports = {
|
|
|
79
86
|
// ↓ for HMR
|
|
80
87
|
webSocketURL: {
|
|
81
88
|
protocol: 'wss',
|
|
89
|
+
hostname: 'xxx', // <- target hostname
|
|
82
90
|
port: 443,
|
|
83
91
|
},
|
|
84
92
|
},
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
consola
|
|
3
|
+
} from "./chunk-3HKPYCSE.js";
|
|
4
|
+
|
|
1
5
|
// src/index.ts
|
|
2
6
|
import process3 from "process";
|
|
3
7
|
import { createUnplugin } from "unplugin";
|
|
@@ -293,15 +297,14 @@ var CaddyInstant = class {
|
|
|
293
297
|
}
|
|
294
298
|
});
|
|
295
299
|
child.stdout.on("data", (_data) => {
|
|
296
|
-
|
|
300
|
+
consola.info(_data.toString());
|
|
297
301
|
resolve(async () => {
|
|
298
302
|
if (!restore)
|
|
299
303
|
return;
|
|
300
|
-
if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
304
|
+
if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
|
|
305
|
+
consola.success("restore host success\n");
|
|
306
|
+
else
|
|
307
|
+
consola.fail("restore host failed\n");
|
|
305
308
|
child.kill();
|
|
306
309
|
});
|
|
307
310
|
});
|
|
@@ -324,11 +327,13 @@ var unpluginFactory = (options) => ({
|
|
|
324
327
|
target = ""
|
|
325
328
|
} = options;
|
|
326
329
|
if (!target) {
|
|
327
|
-
|
|
330
|
+
consola.fail("please provide target");
|
|
328
331
|
return;
|
|
329
332
|
}
|
|
333
|
+
const _printUrls = server.printUrls;
|
|
330
334
|
server.printUrls = () => {
|
|
331
335
|
var _a;
|
|
336
|
+
_printUrls();
|
|
332
337
|
let source = `localhost:${config.server.port}`;
|
|
333
338
|
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
334
339
|
if (url) {
|
|
@@ -342,7 +347,7 @@ var unpluginFactory = (options) => ({
|
|
|
342
347
|
base
|
|
343
348
|
}).then((stop) => {
|
|
344
349
|
const colorUrl = (url2) => c.green(url2.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
|
|
345
|
-
|
|
350
|
+
consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
|
|
346
351
|
process3.on("SIGINT", async () => {
|
|
347
352
|
await stop();
|
|
348
353
|
server.close();
|
|
@@ -350,7 +355,7 @@ var unpluginFactory = (options) => ({
|
|
|
350
355
|
});
|
|
351
356
|
});
|
|
352
357
|
} catch (e) {
|
|
353
|
-
|
|
358
|
+
consola.error(e);
|
|
354
359
|
}
|
|
355
360
|
};
|
|
356
361
|
}
|
|
@@ -360,7 +365,7 @@ var unpluginFactory = (options) => ({
|
|
|
360
365
|
target = ""
|
|
361
366
|
} = options;
|
|
362
367
|
if (!target) {
|
|
363
|
-
|
|
368
|
+
consola.fail("please provide target");
|
|
364
369
|
return;
|
|
365
370
|
}
|
|
366
371
|
try {
|
|
@@ -374,7 +379,7 @@ var unpluginFactory = (options) => ({
|
|
|
374
379
|
compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
|
|
375
380
|
if (stats.hasErrors())
|
|
376
381
|
return;
|
|
377
|
-
|
|
382
|
+
consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
|
|
378
383
|
});
|
|
379
384
|
process3.on("SIGINT", async () => {
|
|
380
385
|
await stop();
|
|
@@ -384,7 +389,7 @@ var unpluginFactory = (options) => ({
|
|
|
384
389
|
throw e;
|
|
385
390
|
});
|
|
386
391
|
} catch (e) {
|
|
387
|
-
|
|
392
|
+
consola.error(e);
|
|
388
393
|
}
|
|
389
394
|
}
|
|
390
395
|
});
|
package/dist/esbuild.cjs
CHANGED
|
@@ -40,6 +40,12 @@ var import_node_process3 = __toESM(require("process"), 1);
|
|
|
40
40
|
var import_unplugin = require("unplugin");
|
|
41
41
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
42
42
|
|
|
43
|
+
// src/utils.ts
|
|
44
|
+
var import_consola = require("consola");
|
|
45
|
+
var consola = (0, import_consola.createConsola)({
|
|
46
|
+
level: 3
|
|
47
|
+
}).withTag("reverse-proxy");
|
|
48
|
+
|
|
43
49
|
// src/caddy/index.ts
|
|
44
50
|
var import_node_os = require("os");
|
|
45
51
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
@@ -330,15 +336,14 @@ var CaddyInstant = class {
|
|
|
330
336
|
}
|
|
331
337
|
});
|
|
332
338
|
child.stdout.on("data", (_data) => {
|
|
333
|
-
|
|
339
|
+
consola.info(_data.toString());
|
|
334
340
|
resolve(async () => {
|
|
335
341
|
if (!restore)
|
|
336
342
|
return;
|
|
337
|
-
if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
}
|
|
343
|
+
if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
|
|
344
|
+
consola.success("restore host success\n");
|
|
345
|
+
else
|
|
346
|
+
consola.fail("restore host failed\n");
|
|
342
347
|
child.kill();
|
|
343
348
|
});
|
|
344
349
|
});
|
|
@@ -361,11 +366,13 @@ var unpluginFactory = (options) => ({
|
|
|
361
366
|
target = ""
|
|
362
367
|
} = options;
|
|
363
368
|
if (!target) {
|
|
364
|
-
|
|
369
|
+
consola.fail("please provide target");
|
|
365
370
|
return;
|
|
366
371
|
}
|
|
372
|
+
const _printUrls = server.printUrls;
|
|
367
373
|
server.printUrls = () => {
|
|
368
374
|
var _a;
|
|
375
|
+
_printUrls();
|
|
369
376
|
let source = `localhost:${config.server.port}`;
|
|
370
377
|
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
371
378
|
if (url) {
|
|
@@ -379,7 +386,7 @@ var unpluginFactory = (options) => ({
|
|
|
379
386
|
base
|
|
380
387
|
}).then((stop) => {
|
|
381
388
|
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
382
|
-
|
|
389
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
|
|
383
390
|
import_node_process3.default.on("SIGINT", async () => {
|
|
384
391
|
await stop();
|
|
385
392
|
server.close();
|
|
@@ -387,7 +394,7 @@ var unpluginFactory = (options) => ({
|
|
|
387
394
|
});
|
|
388
395
|
});
|
|
389
396
|
} catch (e) {
|
|
390
|
-
|
|
397
|
+
consola.error(e);
|
|
391
398
|
}
|
|
392
399
|
};
|
|
393
400
|
}
|
|
@@ -397,7 +404,7 @@ var unpluginFactory = (options) => ({
|
|
|
397
404
|
target = ""
|
|
398
405
|
} = options;
|
|
399
406
|
if (!target) {
|
|
400
|
-
|
|
407
|
+
consola.fail("please provide target");
|
|
401
408
|
return;
|
|
402
409
|
}
|
|
403
410
|
try {
|
|
@@ -411,7 +418,7 @@ var unpluginFactory = (options) => ({
|
|
|
411
418
|
compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
|
|
412
419
|
if (stats.hasErrors())
|
|
413
420
|
return;
|
|
414
|
-
|
|
421
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
|
|
415
422
|
});
|
|
416
423
|
import_node_process3.default.on("SIGINT", async () => {
|
|
417
424
|
await stop();
|
|
@@ -421,7 +428,7 @@ var unpluginFactory = (options) => ({
|
|
|
421
428
|
throw e;
|
|
422
429
|
});
|
|
423
430
|
} catch (e) {
|
|
424
|
-
|
|
431
|
+
consola.error(e);
|
|
425
432
|
}
|
|
426
433
|
}
|
|
427
434
|
});
|
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,12 @@ var import_node_process3 = __toESM(require("process"), 1);
|
|
|
39
39
|
var import_unplugin = require("unplugin");
|
|
40
40
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
41
41
|
|
|
42
|
+
// src/utils.ts
|
|
43
|
+
var import_consola = require("consola");
|
|
44
|
+
var consola = (0, import_consola.createConsola)({
|
|
45
|
+
level: 3
|
|
46
|
+
}).withTag("reverse-proxy");
|
|
47
|
+
|
|
42
48
|
// src/caddy/index.ts
|
|
43
49
|
var import_node_os = require("os");
|
|
44
50
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
@@ -329,15 +335,14 @@ var CaddyInstant = class {
|
|
|
329
335
|
}
|
|
330
336
|
});
|
|
331
337
|
child.stdout.on("data", (_data) => {
|
|
332
|
-
|
|
338
|
+
consola.info(_data.toString());
|
|
333
339
|
resolve(async () => {
|
|
334
340
|
if (!restore)
|
|
335
341
|
return;
|
|
336
|
-
if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
342
|
+
if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
|
|
343
|
+
consola.success("restore host success\n");
|
|
344
|
+
else
|
|
345
|
+
consola.fail("restore host failed\n");
|
|
341
346
|
child.kill();
|
|
342
347
|
});
|
|
343
348
|
});
|
|
@@ -360,11 +365,13 @@ var unpluginFactory = (options) => ({
|
|
|
360
365
|
target = ""
|
|
361
366
|
} = options;
|
|
362
367
|
if (!target) {
|
|
363
|
-
|
|
368
|
+
consola.fail("please provide target");
|
|
364
369
|
return;
|
|
365
370
|
}
|
|
371
|
+
const _printUrls = server.printUrls;
|
|
366
372
|
server.printUrls = () => {
|
|
367
373
|
var _a;
|
|
374
|
+
_printUrls();
|
|
368
375
|
let source = `localhost:${config.server.port}`;
|
|
369
376
|
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
370
377
|
if (url) {
|
|
@@ -378,7 +385,7 @@ var unpluginFactory = (options) => ({
|
|
|
378
385
|
base
|
|
379
386
|
}).then((stop) => {
|
|
380
387
|
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
381
|
-
|
|
388
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
|
|
382
389
|
import_node_process3.default.on("SIGINT", async () => {
|
|
383
390
|
await stop();
|
|
384
391
|
server.close();
|
|
@@ -386,7 +393,7 @@ var unpluginFactory = (options) => ({
|
|
|
386
393
|
});
|
|
387
394
|
});
|
|
388
395
|
} catch (e) {
|
|
389
|
-
|
|
396
|
+
consola.error(e);
|
|
390
397
|
}
|
|
391
398
|
};
|
|
392
399
|
}
|
|
@@ -396,7 +403,7 @@ var unpluginFactory = (options) => ({
|
|
|
396
403
|
target = ""
|
|
397
404
|
} = options;
|
|
398
405
|
if (!target) {
|
|
399
|
-
|
|
406
|
+
consola.fail("please provide target");
|
|
400
407
|
return;
|
|
401
408
|
}
|
|
402
409
|
try {
|
|
@@ -410,7 +417,7 @@ var unpluginFactory = (options) => ({
|
|
|
410
417
|
compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
|
|
411
418
|
if (stats.hasErrors())
|
|
412
419
|
return;
|
|
413
|
-
|
|
420
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
|
|
414
421
|
});
|
|
415
422
|
import_node_process3.default.on("SIGINT", async () => {
|
|
416
423
|
await stop();
|
|
@@ -420,7 +427,7 @@ var unpluginFactory = (options) => ({
|
|
|
420
427
|
throw e;
|
|
421
428
|
});
|
|
422
429
|
} catch (e) {
|
|
423
|
-
|
|
430
|
+
consola.error(e);
|
|
424
431
|
}
|
|
425
432
|
}
|
|
426
433
|
});
|
package/dist/index.js
CHANGED
package/dist/nuxt.cjs
CHANGED
|
@@ -43,6 +43,12 @@ var import_node_process3 = __toESM(require("process"), 1);
|
|
|
43
43
|
var import_unplugin = require("unplugin");
|
|
44
44
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
45
45
|
|
|
46
|
+
// src/utils.ts
|
|
47
|
+
var import_consola = require("consola");
|
|
48
|
+
var consola = (0, import_consola.createConsola)({
|
|
49
|
+
level: 3
|
|
50
|
+
}).withTag("reverse-proxy");
|
|
51
|
+
|
|
46
52
|
// src/caddy/index.ts
|
|
47
53
|
var import_node_os = require("os");
|
|
48
54
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
@@ -333,15 +339,14 @@ var CaddyInstant = class {
|
|
|
333
339
|
}
|
|
334
340
|
});
|
|
335
341
|
child.stdout.on("data", (_data) => {
|
|
336
|
-
|
|
342
|
+
consola.info(_data.toString());
|
|
337
343
|
resolve(async () => {
|
|
338
344
|
if (!restore)
|
|
339
345
|
return;
|
|
340
|
-
if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
}
|
|
346
|
+
if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
|
|
347
|
+
consola.success("restore host success\n");
|
|
348
|
+
else
|
|
349
|
+
consola.fail("restore host failed\n");
|
|
345
350
|
child.kill();
|
|
346
351
|
});
|
|
347
352
|
});
|
|
@@ -364,11 +369,13 @@ var unpluginFactory = (options) => ({
|
|
|
364
369
|
target = ""
|
|
365
370
|
} = options;
|
|
366
371
|
if (!target) {
|
|
367
|
-
|
|
372
|
+
consola.fail("please provide target");
|
|
368
373
|
return;
|
|
369
374
|
}
|
|
375
|
+
const _printUrls = server.printUrls;
|
|
370
376
|
server.printUrls = () => {
|
|
371
377
|
var _a;
|
|
378
|
+
_printUrls();
|
|
372
379
|
let source = `localhost:${config.server.port}`;
|
|
373
380
|
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
374
381
|
if (url) {
|
|
@@ -382,7 +389,7 @@ var unpluginFactory = (options) => ({
|
|
|
382
389
|
base
|
|
383
390
|
}).then((stop) => {
|
|
384
391
|
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
385
|
-
|
|
392
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
|
|
386
393
|
import_node_process3.default.on("SIGINT", async () => {
|
|
387
394
|
await stop();
|
|
388
395
|
server.close();
|
|
@@ -390,7 +397,7 @@ var unpluginFactory = (options) => ({
|
|
|
390
397
|
});
|
|
391
398
|
});
|
|
392
399
|
} catch (e) {
|
|
393
|
-
|
|
400
|
+
consola.error(e);
|
|
394
401
|
}
|
|
395
402
|
};
|
|
396
403
|
}
|
|
@@ -400,7 +407,7 @@ var unpluginFactory = (options) => ({
|
|
|
400
407
|
target = ""
|
|
401
408
|
} = options;
|
|
402
409
|
if (!target) {
|
|
403
|
-
|
|
410
|
+
consola.fail("please provide target");
|
|
404
411
|
return;
|
|
405
412
|
}
|
|
406
413
|
try {
|
|
@@ -414,7 +421,7 @@ var unpluginFactory = (options) => ({
|
|
|
414
421
|
compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
|
|
415
422
|
if (stats.hasErrors())
|
|
416
423
|
return;
|
|
417
|
-
|
|
424
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
|
|
418
425
|
});
|
|
419
426
|
import_node_process3.default.on("SIGINT", async () => {
|
|
420
427
|
await stop();
|
|
@@ -424,7 +431,7 @@ var unpluginFactory = (options) => ({
|
|
|
424
431
|
throw e;
|
|
425
432
|
});
|
|
426
433
|
} catch (e) {
|
|
427
|
-
|
|
434
|
+
consola.error(e);
|
|
428
435
|
}
|
|
429
436
|
}
|
|
430
437
|
});
|
package/dist/nuxt.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
vite_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-HSJJYR6E.js";
|
|
4
4
|
import {
|
|
5
5
|
webpack_default
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-JN5C2QIT.js";
|
|
7
|
+
import "./chunk-H5P77DDT.js";
|
|
8
|
+
import "./chunk-3HKPYCSE.js";
|
|
8
9
|
|
|
9
10
|
// src/nuxt.ts
|
|
10
11
|
import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
|
package/dist/rollup.cjs
CHANGED
|
@@ -40,6 +40,12 @@ var import_node_process3 = __toESM(require("process"), 1);
|
|
|
40
40
|
var import_unplugin = require("unplugin");
|
|
41
41
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
42
42
|
|
|
43
|
+
// src/utils.ts
|
|
44
|
+
var import_consola = require("consola");
|
|
45
|
+
var consola = (0, import_consola.createConsola)({
|
|
46
|
+
level: 3
|
|
47
|
+
}).withTag("reverse-proxy");
|
|
48
|
+
|
|
43
49
|
// src/caddy/index.ts
|
|
44
50
|
var import_node_os = require("os");
|
|
45
51
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
@@ -330,15 +336,14 @@ var CaddyInstant = class {
|
|
|
330
336
|
}
|
|
331
337
|
});
|
|
332
338
|
child.stdout.on("data", (_data) => {
|
|
333
|
-
|
|
339
|
+
consola.info(_data.toString());
|
|
334
340
|
resolve(async () => {
|
|
335
341
|
if (!restore)
|
|
336
342
|
return;
|
|
337
|
-
if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
}
|
|
343
|
+
if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
|
|
344
|
+
consola.success("restore host success\n");
|
|
345
|
+
else
|
|
346
|
+
consola.fail("restore host failed\n");
|
|
342
347
|
child.kill();
|
|
343
348
|
});
|
|
344
349
|
});
|
|
@@ -361,11 +366,13 @@ var unpluginFactory = (options) => ({
|
|
|
361
366
|
target = ""
|
|
362
367
|
} = options;
|
|
363
368
|
if (!target) {
|
|
364
|
-
|
|
369
|
+
consola.fail("please provide target");
|
|
365
370
|
return;
|
|
366
371
|
}
|
|
372
|
+
const _printUrls = server.printUrls;
|
|
367
373
|
server.printUrls = () => {
|
|
368
374
|
var _a;
|
|
375
|
+
_printUrls();
|
|
369
376
|
let source = `localhost:${config.server.port}`;
|
|
370
377
|
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
371
378
|
if (url) {
|
|
@@ -379,7 +386,7 @@ var unpluginFactory = (options) => ({
|
|
|
379
386
|
base
|
|
380
387
|
}).then((stop) => {
|
|
381
388
|
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
382
|
-
|
|
389
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
|
|
383
390
|
import_node_process3.default.on("SIGINT", async () => {
|
|
384
391
|
await stop();
|
|
385
392
|
server.close();
|
|
@@ -387,7 +394,7 @@ var unpluginFactory = (options) => ({
|
|
|
387
394
|
});
|
|
388
395
|
});
|
|
389
396
|
} catch (e) {
|
|
390
|
-
|
|
397
|
+
consola.error(e);
|
|
391
398
|
}
|
|
392
399
|
};
|
|
393
400
|
}
|
|
@@ -397,7 +404,7 @@ var unpluginFactory = (options) => ({
|
|
|
397
404
|
target = ""
|
|
398
405
|
} = options;
|
|
399
406
|
if (!target) {
|
|
400
|
-
|
|
407
|
+
consola.fail("please provide target");
|
|
401
408
|
return;
|
|
402
409
|
}
|
|
403
410
|
try {
|
|
@@ -411,7 +418,7 @@ var unpluginFactory = (options) => ({
|
|
|
411
418
|
compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
|
|
412
419
|
if (stats.hasErrors())
|
|
413
420
|
return;
|
|
414
|
-
|
|
421
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
|
|
415
422
|
});
|
|
416
423
|
import_node_process3.default.on("SIGINT", async () => {
|
|
417
424
|
await stop();
|
|
@@ -421,7 +428,7 @@ var unpluginFactory = (options) => ({
|
|
|
421
428
|
throw e;
|
|
422
429
|
});
|
|
423
430
|
} catch (e) {
|
|
424
|
-
|
|
431
|
+
consola.error(e);
|
|
425
432
|
}
|
|
426
433
|
}
|
|
427
434
|
});
|
package/dist/rollup.js
CHANGED
package/dist/utils.cjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/utils.ts
|
|
21
|
+
var utils_exports = {};
|
|
22
|
+
__export(utils_exports, {
|
|
23
|
+
consola: () => consola
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(utils_exports);
|
|
26
|
+
var import_consola = require("consola");
|
|
27
|
+
var consola = (0, import_consola.createConsola)({
|
|
28
|
+
level: 3
|
|
29
|
+
}).withTag("reverse-proxy");
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
consola
|
|
33
|
+
});
|
|
34
|
+
exports.default = module.exports;
|
package/dist/utils.d.cts
ADDED
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
package/dist/vite.cjs
CHANGED
|
@@ -40,6 +40,12 @@ var import_node_process3 = __toESM(require("process"), 1);
|
|
|
40
40
|
var import_unplugin = require("unplugin");
|
|
41
41
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
42
42
|
|
|
43
|
+
// src/utils.ts
|
|
44
|
+
var import_consola = require("consola");
|
|
45
|
+
var consola = (0, import_consola.createConsola)({
|
|
46
|
+
level: 3
|
|
47
|
+
}).withTag("reverse-proxy");
|
|
48
|
+
|
|
43
49
|
// src/caddy/index.ts
|
|
44
50
|
var import_node_os = require("os");
|
|
45
51
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
@@ -330,15 +336,14 @@ var CaddyInstant = class {
|
|
|
330
336
|
}
|
|
331
337
|
});
|
|
332
338
|
child.stdout.on("data", (_data) => {
|
|
333
|
-
|
|
339
|
+
consola.info(_data.toString());
|
|
334
340
|
resolve(async () => {
|
|
335
341
|
if (!restore)
|
|
336
342
|
return;
|
|
337
|
-
if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
}
|
|
343
|
+
if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
|
|
344
|
+
consola.success("restore host success\n");
|
|
345
|
+
else
|
|
346
|
+
consola.fail("restore host failed\n");
|
|
342
347
|
child.kill();
|
|
343
348
|
});
|
|
344
349
|
});
|
|
@@ -361,11 +366,13 @@ var unpluginFactory = (options) => ({
|
|
|
361
366
|
target = ""
|
|
362
367
|
} = options;
|
|
363
368
|
if (!target) {
|
|
364
|
-
|
|
369
|
+
consola.fail("please provide target");
|
|
365
370
|
return;
|
|
366
371
|
}
|
|
372
|
+
const _printUrls = server.printUrls;
|
|
367
373
|
server.printUrls = () => {
|
|
368
374
|
var _a;
|
|
375
|
+
_printUrls();
|
|
369
376
|
let source = `localhost:${config.server.port}`;
|
|
370
377
|
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
371
378
|
if (url) {
|
|
@@ -379,7 +386,7 @@ var unpluginFactory = (options) => ({
|
|
|
379
386
|
base
|
|
380
387
|
}).then((stop) => {
|
|
381
388
|
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
382
|
-
|
|
389
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
|
|
383
390
|
import_node_process3.default.on("SIGINT", async () => {
|
|
384
391
|
await stop();
|
|
385
392
|
server.close();
|
|
@@ -387,7 +394,7 @@ var unpluginFactory = (options) => ({
|
|
|
387
394
|
});
|
|
388
395
|
});
|
|
389
396
|
} catch (e) {
|
|
390
|
-
|
|
397
|
+
consola.error(e);
|
|
391
398
|
}
|
|
392
399
|
};
|
|
393
400
|
}
|
|
@@ -397,7 +404,7 @@ var unpluginFactory = (options) => ({
|
|
|
397
404
|
target = ""
|
|
398
405
|
} = options;
|
|
399
406
|
if (!target) {
|
|
400
|
-
|
|
407
|
+
consola.fail("please provide target");
|
|
401
408
|
return;
|
|
402
409
|
}
|
|
403
410
|
try {
|
|
@@ -411,7 +418,7 @@ var unpluginFactory = (options) => ({
|
|
|
411
418
|
compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
|
|
412
419
|
if (stats.hasErrors())
|
|
413
420
|
return;
|
|
414
|
-
|
|
421
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
|
|
415
422
|
});
|
|
416
423
|
import_node_process3.default.on("SIGINT", async () => {
|
|
417
424
|
await stop();
|
|
@@ -421,7 +428,7 @@ var unpluginFactory = (options) => ({
|
|
|
421
428
|
throw e;
|
|
422
429
|
});
|
|
423
430
|
} catch (e) {
|
|
424
|
-
|
|
431
|
+
consola.error(e);
|
|
425
432
|
}
|
|
426
433
|
}
|
|
427
434
|
});
|
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -40,6 +40,12 @@ var import_node_process3 = __toESM(require("process"), 1);
|
|
|
40
40
|
var import_unplugin = require("unplugin");
|
|
41
41
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
42
42
|
|
|
43
|
+
// src/utils.ts
|
|
44
|
+
var import_consola = require("consola");
|
|
45
|
+
var consola = (0, import_consola.createConsola)({
|
|
46
|
+
level: 3
|
|
47
|
+
}).withTag("reverse-proxy");
|
|
48
|
+
|
|
43
49
|
// src/caddy/index.ts
|
|
44
50
|
var import_node_os = require("os");
|
|
45
51
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
@@ -330,15 +336,14 @@ var CaddyInstant = class {
|
|
|
330
336
|
}
|
|
331
337
|
});
|
|
332
338
|
child.stdout.on("data", (_data) => {
|
|
333
|
-
|
|
339
|
+
consola.info(_data.toString());
|
|
334
340
|
resolve(async () => {
|
|
335
341
|
if (!restore)
|
|
336
342
|
return;
|
|
337
|
-
if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
}
|
|
343
|
+
if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
|
|
344
|
+
consola.success("restore host success\n");
|
|
345
|
+
else
|
|
346
|
+
consola.fail("restore host failed\n");
|
|
342
347
|
child.kill();
|
|
343
348
|
});
|
|
344
349
|
});
|
|
@@ -361,11 +366,13 @@ var unpluginFactory = (options) => ({
|
|
|
361
366
|
target = ""
|
|
362
367
|
} = options;
|
|
363
368
|
if (!target) {
|
|
364
|
-
|
|
369
|
+
consola.fail("please provide target");
|
|
365
370
|
return;
|
|
366
371
|
}
|
|
372
|
+
const _printUrls = server.printUrls;
|
|
367
373
|
server.printUrls = () => {
|
|
368
374
|
var _a;
|
|
375
|
+
_printUrls();
|
|
369
376
|
let source = `localhost:${config.server.port}`;
|
|
370
377
|
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
371
378
|
if (url) {
|
|
@@ -379,7 +386,7 @@ var unpluginFactory = (options) => ({
|
|
|
379
386
|
base
|
|
380
387
|
}).then((stop) => {
|
|
381
388
|
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
382
|
-
|
|
389
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
|
|
383
390
|
import_node_process3.default.on("SIGINT", async () => {
|
|
384
391
|
await stop();
|
|
385
392
|
server.close();
|
|
@@ -387,7 +394,7 @@ var unpluginFactory = (options) => ({
|
|
|
387
394
|
});
|
|
388
395
|
});
|
|
389
396
|
} catch (e) {
|
|
390
|
-
|
|
397
|
+
consola.error(e);
|
|
391
398
|
}
|
|
392
399
|
};
|
|
393
400
|
}
|
|
@@ -397,7 +404,7 @@ var unpluginFactory = (options) => ({
|
|
|
397
404
|
target = ""
|
|
398
405
|
} = options;
|
|
399
406
|
if (!target) {
|
|
400
|
-
|
|
407
|
+
consola.fail("please provide target");
|
|
401
408
|
return;
|
|
402
409
|
}
|
|
403
410
|
try {
|
|
@@ -411,7 +418,7 @@ var unpluginFactory = (options) => ({
|
|
|
411
418
|
compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
|
|
412
419
|
if (stats.hasErrors())
|
|
413
420
|
return;
|
|
414
|
-
|
|
421
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
|
|
415
422
|
});
|
|
416
423
|
import_node_process3.default.on("SIGINT", async () => {
|
|
417
424
|
await stop();
|
|
@@ -421,7 +428,7 @@ var unpluginFactory = (options) => ({
|
|
|
421
428
|
throw e;
|
|
422
429
|
});
|
|
423
430
|
} catch (e) {
|
|
424
|
-
|
|
431
|
+
consola.error(e);
|
|
425
432
|
}
|
|
426
433
|
}
|
|
427
434
|
});
|
package/dist/webpack.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-https-reverse-proxy",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.8",
|
|
5
5
|
"packageManager": "pnpm@8.6.12",
|
|
6
6
|
"description": "",
|
|
7
7
|
"license": "MIT",
|
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
},
|
|
72
72
|
"files": [
|
|
73
73
|
"dist",
|
|
74
|
+
"scripts/postinstall.ts",
|
|
74
75
|
"src"
|
|
75
76
|
],
|
|
76
77
|
"peerDependencies": {
|
|
@@ -102,6 +103,7 @@
|
|
|
102
103
|
}
|
|
103
104
|
},
|
|
104
105
|
"dependencies": {
|
|
106
|
+
"consola": "^3.2.3",
|
|
105
107
|
"esno": "^0.17.0",
|
|
106
108
|
"got-cjs": "^12.5.4",
|
|
107
109
|
"hostile": "^1.3.3",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { existsSync, unlinkSync } from 'node:fs'
|
|
2
|
+
import { consola } from '../src/utils'
|
|
3
|
+
import { download } from '../src/caddy'
|
|
4
|
+
import { caddyPath } from '../src/caddy/constants'
|
|
5
|
+
|
|
6
|
+
async function run() {
|
|
7
|
+
try {
|
|
8
|
+
existsSync(caddyPath) && unlinkSync(caddyPath)
|
|
9
|
+
await download()
|
|
10
|
+
}
|
|
11
|
+
catch (e: any) {
|
|
12
|
+
consola.error(e.code)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
run()
|
package/src/caddy/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { HttpProxyAgent } from 'http-proxy-agent'
|
|
|
7
7
|
import { HttpsProxyAgent } from 'https-proxy-agent'
|
|
8
8
|
import * as hostile from 'hostile'
|
|
9
9
|
import kill from 'kill-port'
|
|
10
|
+
import { consola } from '../utils'
|
|
10
11
|
import { caddyPath, supportList } from './constants'
|
|
11
12
|
import { tryPort } from './utils'
|
|
12
13
|
|
|
@@ -53,7 +54,7 @@ export async function download() {
|
|
|
53
54
|
chmodSync(caddyPath, 0o755)
|
|
54
55
|
resolve(caddyPath)
|
|
55
56
|
}).on('error', (err) => {
|
|
56
|
-
//
|
|
57
|
+
// consola.error(err)
|
|
57
58
|
reject(err)
|
|
58
59
|
})
|
|
59
60
|
})
|
|
@@ -191,19 +192,17 @@ export class CaddyInstant {
|
|
|
191
192
|
})
|
|
192
193
|
|
|
193
194
|
child.stdout.on('data', (_data) => {
|
|
194
|
-
|
|
195
|
-
console.log(_data.toString())
|
|
195
|
+
consola.info(_data.toString())
|
|
196
196
|
resolve(async () => {
|
|
197
197
|
if (!restore)
|
|
198
198
|
return
|
|
199
199
|
|
|
200
|
-
if (await this.restoreHost(source.split(':')[0], target.split(':')[0]))
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
200
|
+
if (await this.restoreHost(source.split(':')[0], target.split(':')[0]))
|
|
201
|
+
consola.success('restore host success\n')
|
|
202
|
+
|
|
203
|
+
else
|
|
204
|
+
consola.fail('restore host failed\n')
|
|
205
|
+
|
|
207
206
|
child.kill()
|
|
208
207
|
})
|
|
209
208
|
})
|
package/src/caddy/utils.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { UnpluginFactory } from 'unplugin'
|
|
|
3
3
|
import { createUnplugin } from 'unplugin'
|
|
4
4
|
import type { ResolvedConfig } from 'vite'
|
|
5
5
|
import c from 'picocolors'
|
|
6
|
+
import { consola } from './utils'
|
|
6
7
|
import type { Options } from './types'
|
|
7
8
|
import { CaddyInstant } from './caddy'
|
|
8
9
|
|
|
@@ -22,11 +23,12 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
22
23
|
target = '',
|
|
23
24
|
} = options
|
|
24
25
|
if (!target) {
|
|
25
|
-
|
|
26
|
-
console.log('please provide target')
|
|
26
|
+
consola.fail('please provide target')
|
|
27
27
|
return
|
|
28
28
|
}
|
|
29
|
+
const _printUrls = server.printUrls
|
|
29
30
|
server.printUrls = () => {
|
|
31
|
+
_printUrls()
|
|
30
32
|
let source = `localhost:${config.server.port}`
|
|
31
33
|
const url = server.resolvedUrls?.local[0]
|
|
32
34
|
if (url) {
|
|
@@ -40,8 +42,7 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
40
42
|
base,
|
|
41
43
|
}).then((stop) => {
|
|
42
44
|
const colorUrl = (url: string) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`))
|
|
43
|
-
|
|
44
|
-
console.log(` ${c.green('➜')} ${c.bold('run caddy reverse proxy success')}: ${colorUrl(`https://${target}${base}`)}`)
|
|
45
|
+
consola.success(` ${c.green('➜')} ${c.bold('run caddy reverse proxy success')}: ${colorUrl(`https://${target}${base}`)}`)
|
|
45
46
|
|
|
46
47
|
process.on('SIGINT', async () => {
|
|
47
48
|
await stop()
|
|
@@ -51,7 +52,7 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
51
52
|
})
|
|
52
53
|
}
|
|
53
54
|
catch (e) {
|
|
54
|
-
|
|
55
|
+
consola.error(e)
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
},
|
|
@@ -61,8 +62,7 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
61
62
|
target = '',
|
|
62
63
|
} = options
|
|
63
64
|
if (!target) {
|
|
64
|
-
|
|
65
|
-
console.log('please provide target')
|
|
65
|
+
consola.fail('please provide target')
|
|
66
66
|
return
|
|
67
67
|
}
|
|
68
68
|
try {
|
|
@@ -82,8 +82,7 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
82
82
|
if (stats.hasErrors())
|
|
83
83
|
return
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
console.log(` ${c.green('➜')} ${c.bold('run caddy reverse proxy success')}: ${colorUrl(`https://${target}`)}`)
|
|
85
|
+
consola.success(` ${c.green('➜')} ${c.bold('run caddy reverse proxy success')}: ${colorUrl(`https://${target}`)}`)
|
|
87
86
|
})
|
|
88
87
|
|
|
89
88
|
process.on('SIGINT', async () => {
|
|
@@ -95,7 +94,7 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
95
94
|
})
|
|
96
95
|
}
|
|
97
96
|
catch (e) {
|
|
98
|
-
|
|
97
|
+
consola.error(e)
|
|
99
98
|
}
|
|
100
99
|
},
|
|
101
100
|
})
|