unplugin-https-reverse-proxy 0.0.10 → 0.0.12

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 CHANGED
@@ -16,7 +16,9 @@ UHRP_AUTO_INSTALL_CADDY=true npm i unplugin-https-reverse-proxy --save-dev
16
16
 
17
17
  ```ts
18
18
  interface Options {
19
+ enable?: boolean // <- default: true
19
20
  target: string // <- https target hostname
21
+ showCaddyLog?: boolean // <- default: false
20
22
  }
21
23
  ```
22
24
 
@@ -25,11 +27,11 @@ interface Options {
25
27
 
26
28
  ```ts
27
29
  // vite.config.ts
28
- import Starter from 'unplugin-https-reverse-proxy/vite'
30
+ import HttpsReverseProxy from 'unplugin-https-reverse-proxy/vite'
29
31
 
30
32
  export default defineConfig({
31
33
  plugins: [
32
- Starter({ /* options */ }),
34
+ HttpsReverseProxy({ /* options */ }),
33
35
  ],
34
36
  })
35
37
  ```
@@ -115,4 +117,10 @@ sudo -E npm run dev # your dev script
115
117
  # windows
116
118
  # use powershell as administrator
117
119
  npm run dev # your dev script
118
- ```
120
+ ```
121
+
122
+ If your broswer shows a not trusted certificate warning, please check the keychain.
123
+
124
+ ![keychain](https://github.com/zcf0508/unplugin-https-reverse-proxy/blob/main/images/Snipaste_2023-11-16_16-59-55.png)
125
+
126
+ More info, you can check [caddy about CA Root](https://caddyserver.com/docs/automatic-https#ca-root).
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-AJ47BPUG.js";
3
+ } from "./chunk-WUSTJHAZ.js";
4
4
 
5
5
  // src/webpack.ts
6
6
  import { createWebpackPlugin } from "unplugin";
@@ -275,7 +275,8 @@ var CaddyInstant = class {
275
275
  source = source.replace("0.0.0.0", "127.0.0.1").replace("localhost", "127.0.0.1");
276
276
  const {
277
277
  restore = true,
278
- base = "/"
278
+ base = "/",
279
+ showCaddyLog = false
279
280
  } = options || {};
280
281
  if (!this.inited)
281
282
  await this.init();
@@ -291,9 +292,13 @@ var CaddyInstant = class {
291
292
  return reject(err);
292
293
  });
293
294
  child.stderr.on("data", (data) => {
294
- if (data.toString().includes("Error")) {
295
- child.kill();
296
- return reject(data.toString());
295
+ const lines = data.toString().split("\n").map((line) => line.trim());
296
+ for (const line of lines) {
297
+ showCaddyLog && line && console.info(line);
298
+ if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
299
+ consola.error(line);
300
+ return reject(line);
301
+ }
297
302
  }
298
303
  });
299
304
  child.stdout.on("data", (_data) => {
@@ -324,8 +329,11 @@ var unpluginFactory = (options) => ({
324
329
  },
325
330
  configureServer(server) {
326
331
  const {
332
+ enable = true,
327
333
  target = ""
328
334
  } = options;
335
+ if (!enable)
336
+ return;
329
337
  if (!target) {
330
338
  consola.fail("please provide target");
331
339
  return;
@@ -344,7 +352,8 @@ var unpluginFactory = (options) => ({
344
352
  try {
345
353
  const caddy2 = new CaddyInstant();
346
354
  caddy2.run(source, target, {
347
- base
355
+ base,
356
+ showCaddyLog: options.showCaddyLog
348
357
  }).then((stop) => {
349
358
  const colorUrl = (url2) => c.green(url2.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
350
359
  consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
@@ -353,6 +362,8 @@ var unpluginFactory = (options) => ({
353
362
  server.close();
354
363
  process3.exit();
355
364
  });
365
+ }).catch((e) => {
366
+ throw e;
356
367
  });
357
368
  } catch (e) {
358
369
  consola.error(e);
@@ -362,8 +373,11 @@ var unpluginFactory = (options) => ({
362
373
  },
363
374
  webpack(compiler) {
364
375
  const {
376
+ enable = true,
365
377
  target = ""
366
378
  } = options;
379
+ if (!enable)
380
+ return;
367
381
  if (!target) {
368
382
  consola.fail("please provide target");
369
383
  return;
@@ -374,7 +388,9 @@ var unpluginFactory = (options) => ({
374
388
  if (caddy)
375
389
  return;
376
390
  caddy = new CaddyInstant();
377
- caddy.run(source, target).then((stop) => {
391
+ caddy.run(source, target, {
392
+ showCaddyLog: options.showCaddyLog
393
+ }).then((stop) => {
378
394
  const colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
379
395
  compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
380
396
  if (stats.hasErrors())
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-AJ47BPUG.js";
3
+ } from "./chunk-WUSTJHAZ.js";
4
4
 
5
5
  // src/vite.ts
6
6
  import { createVitePlugin } from "unplugin";
package/dist/esbuild.cjs CHANGED
@@ -314,7 +314,8 @@ var CaddyInstant = class {
314
314
  source = source.replace("0.0.0.0", "127.0.0.1").replace("localhost", "127.0.0.1");
315
315
  const {
316
316
  restore = true,
317
- base = "/"
317
+ base = "/",
318
+ showCaddyLog = false
318
319
  } = options || {};
319
320
  if (!this.inited)
320
321
  await this.init();
@@ -330,9 +331,13 @@ var CaddyInstant = class {
330
331
  return reject(err);
331
332
  });
332
333
  child.stderr.on("data", (data) => {
333
- if (data.toString().includes("Error")) {
334
- child.kill();
335
- return reject(data.toString());
334
+ const lines = data.toString().split("\n").map((line) => line.trim());
335
+ for (const line of lines) {
336
+ showCaddyLog && line && console.info(line);
337
+ if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
338
+ consola.error(line);
339
+ return reject(line);
340
+ }
336
341
  }
337
342
  });
338
343
  child.stdout.on("data", (_data) => {
@@ -363,8 +368,11 @@ var unpluginFactory = (options) => ({
363
368
  },
364
369
  configureServer(server) {
365
370
  const {
371
+ enable = true,
366
372
  target = ""
367
373
  } = options;
374
+ if (!enable)
375
+ return;
368
376
  if (!target) {
369
377
  consola.fail("please provide target");
370
378
  return;
@@ -383,7 +391,8 @@ var unpluginFactory = (options) => ({
383
391
  try {
384
392
  const caddy2 = new CaddyInstant();
385
393
  caddy2.run(source, target, {
386
- base
394
+ base,
395
+ showCaddyLog: options.showCaddyLog
387
396
  }).then((stop) => {
388
397
  const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
389
398
  consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
@@ -392,6 +401,8 @@ var unpluginFactory = (options) => ({
392
401
  server.close();
393
402
  import_node_process3.default.exit();
394
403
  });
404
+ }).catch((e) => {
405
+ throw e;
395
406
  });
396
407
  } catch (e) {
397
408
  consola.error(e);
@@ -401,8 +412,11 @@ var unpluginFactory = (options) => ({
401
412
  },
402
413
  webpack(compiler) {
403
414
  const {
415
+ enable = true,
404
416
  target = ""
405
417
  } = options;
418
+ if (!enable)
419
+ return;
406
420
  if (!target) {
407
421
  consola.fail("please provide target");
408
422
  return;
@@ -413,7 +427,9 @@ var unpluginFactory = (options) => ({
413
427
  if (caddy)
414
428
  return;
415
429
  caddy = new CaddyInstant();
416
- caddy.run(source, target).then((stop) => {
430
+ caddy.run(source, target, {
431
+ showCaddyLog: options.showCaddyLog
432
+ }).then((stop) => {
417
433
  const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
418
434
  compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
419
435
  if (stats.hasErrors())
package/dist/esbuild.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-AJ47BPUG.js";
3
+ } from "./chunk-WUSTJHAZ.js";
4
4
  import "./chunk-3HKPYCSE.js";
5
5
 
6
6
  // src/esbuild.ts
package/dist/index.cjs CHANGED
@@ -313,7 +313,8 @@ var CaddyInstant = class {
313
313
  source = source.replace("0.0.0.0", "127.0.0.1").replace("localhost", "127.0.0.1");
314
314
  const {
315
315
  restore = true,
316
- base = "/"
316
+ base = "/",
317
+ showCaddyLog = false
317
318
  } = options || {};
318
319
  if (!this.inited)
319
320
  await this.init();
@@ -329,9 +330,13 @@ var CaddyInstant = class {
329
330
  return reject(err);
330
331
  });
331
332
  child.stderr.on("data", (data) => {
332
- if (data.toString().includes("Error")) {
333
- child.kill();
334
- return reject(data.toString());
333
+ const lines = data.toString().split("\n").map((line) => line.trim());
334
+ for (const line of lines) {
335
+ showCaddyLog && line && console.info(line);
336
+ if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
337
+ consola.error(line);
338
+ return reject(line);
339
+ }
335
340
  }
336
341
  });
337
342
  child.stdout.on("data", (_data) => {
@@ -362,8 +367,11 @@ var unpluginFactory = (options) => ({
362
367
  },
363
368
  configureServer(server) {
364
369
  const {
370
+ enable = true,
365
371
  target = ""
366
372
  } = options;
373
+ if (!enable)
374
+ return;
367
375
  if (!target) {
368
376
  consola.fail("please provide target");
369
377
  return;
@@ -382,7 +390,8 @@ var unpluginFactory = (options) => ({
382
390
  try {
383
391
  const caddy2 = new CaddyInstant();
384
392
  caddy2.run(source, target, {
385
- base
393
+ base,
394
+ showCaddyLog: options.showCaddyLog
386
395
  }).then((stop) => {
387
396
  const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
388
397
  consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
@@ -391,6 +400,8 @@ var unpluginFactory = (options) => ({
391
400
  server.close();
392
401
  import_node_process3.default.exit();
393
402
  });
403
+ }).catch((e) => {
404
+ throw e;
394
405
  });
395
406
  } catch (e) {
396
407
  consola.error(e);
@@ -400,8 +411,11 @@ var unpluginFactory = (options) => ({
400
411
  },
401
412
  webpack(compiler) {
402
413
  const {
414
+ enable = true,
403
415
  target = ""
404
416
  } = options;
417
+ if (!enable)
418
+ return;
405
419
  if (!target) {
406
420
  consola.fail("please provide target");
407
421
  return;
@@ -412,7 +426,9 @@ var unpluginFactory = (options) => ({
412
426
  if (caddy)
413
427
  return;
414
428
  caddy = new CaddyInstant();
415
- caddy.run(source, target).then((stop) => {
429
+ caddy.run(source, target, {
430
+ showCaddyLog: options.showCaddyLog
431
+ }).then((stop) => {
416
432
  const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
417
433
  compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
418
434
  if (stats.hasErrors())
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  src_default,
3
3
  unplugin,
4
4
  unpluginFactory
5
- } from "./chunk-AJ47BPUG.js";
5
+ } from "./chunk-WUSTJHAZ.js";
6
6
  import "./chunk-3HKPYCSE.js";
7
7
  export {
8
8
  src_default as default,
package/dist/nuxt.cjs CHANGED
@@ -317,7 +317,8 @@ var CaddyInstant = class {
317
317
  source = source.replace("0.0.0.0", "127.0.0.1").replace("localhost", "127.0.0.1");
318
318
  const {
319
319
  restore = true,
320
- base = "/"
320
+ base = "/",
321
+ showCaddyLog = false
321
322
  } = options || {};
322
323
  if (!this.inited)
323
324
  await this.init();
@@ -333,9 +334,13 @@ var CaddyInstant = class {
333
334
  return reject(err);
334
335
  });
335
336
  child.stderr.on("data", (data) => {
336
- if (data.toString().includes("Error")) {
337
- child.kill();
338
- return reject(data.toString());
337
+ const lines = data.toString().split("\n").map((line) => line.trim());
338
+ for (const line of lines) {
339
+ showCaddyLog && line && console.info(line);
340
+ if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
341
+ consola.error(line);
342
+ return reject(line);
343
+ }
339
344
  }
340
345
  });
341
346
  child.stdout.on("data", (_data) => {
@@ -366,8 +371,11 @@ var unpluginFactory = (options) => ({
366
371
  },
367
372
  configureServer(server) {
368
373
  const {
374
+ enable = true,
369
375
  target = ""
370
376
  } = options;
377
+ if (!enable)
378
+ return;
371
379
  if (!target) {
372
380
  consola.fail("please provide target");
373
381
  return;
@@ -386,7 +394,8 @@ var unpluginFactory = (options) => ({
386
394
  try {
387
395
  const caddy2 = new CaddyInstant();
388
396
  caddy2.run(source, target, {
389
- base
397
+ base,
398
+ showCaddyLog: options.showCaddyLog
390
399
  }).then((stop) => {
391
400
  const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
392
401
  consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
@@ -395,6 +404,8 @@ var unpluginFactory = (options) => ({
395
404
  server.close();
396
405
  import_node_process3.default.exit();
397
406
  });
407
+ }).catch((e) => {
408
+ throw e;
398
409
  });
399
410
  } catch (e) {
400
411
  consola.error(e);
@@ -404,8 +415,11 @@ var unpluginFactory = (options) => ({
404
415
  },
405
416
  webpack(compiler) {
406
417
  const {
418
+ enable = true,
407
419
  target = ""
408
420
  } = options;
421
+ if (!enable)
422
+ return;
409
423
  if (!target) {
410
424
  consola.fail("please provide target");
411
425
  return;
@@ -416,7 +430,9 @@ var unpluginFactory = (options) => ({
416
430
  if (caddy)
417
431
  return;
418
432
  caddy = new CaddyInstant();
419
- caddy.run(source, target).then((stop) => {
433
+ caddy.run(source, target, {
434
+ showCaddyLog: options.showCaddyLog
435
+ }).then((stop) => {
420
436
  const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
421
437
  compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
422
438
  if (stats.hasErrors())
package/dist/nuxt.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  vite_default
3
- } from "./chunk-FD66DR3R.js";
3
+ } from "./chunk-YP6CZ57A.js";
4
4
  import {
5
5
  webpack_default
6
- } from "./chunk-J2XKEZPC.js";
7
- import "./chunk-AJ47BPUG.js";
6
+ } from "./chunk-ARWX57QE.js";
7
+ import "./chunk-WUSTJHAZ.js";
8
8
  import "./chunk-3HKPYCSE.js";
9
9
 
10
10
  // src/nuxt.ts
package/dist/rollup.cjs CHANGED
@@ -314,7 +314,8 @@ var CaddyInstant = class {
314
314
  source = source.replace("0.0.0.0", "127.0.0.1").replace("localhost", "127.0.0.1");
315
315
  const {
316
316
  restore = true,
317
- base = "/"
317
+ base = "/",
318
+ showCaddyLog = false
318
319
  } = options || {};
319
320
  if (!this.inited)
320
321
  await this.init();
@@ -330,9 +331,13 @@ var CaddyInstant = class {
330
331
  return reject(err);
331
332
  });
332
333
  child.stderr.on("data", (data) => {
333
- if (data.toString().includes("Error")) {
334
- child.kill();
335
- return reject(data.toString());
334
+ const lines = data.toString().split("\n").map((line) => line.trim());
335
+ for (const line of lines) {
336
+ showCaddyLog && line && console.info(line);
337
+ if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
338
+ consola.error(line);
339
+ return reject(line);
340
+ }
336
341
  }
337
342
  });
338
343
  child.stdout.on("data", (_data) => {
@@ -363,8 +368,11 @@ var unpluginFactory = (options) => ({
363
368
  },
364
369
  configureServer(server) {
365
370
  const {
371
+ enable = true,
366
372
  target = ""
367
373
  } = options;
374
+ if (!enable)
375
+ return;
368
376
  if (!target) {
369
377
  consola.fail("please provide target");
370
378
  return;
@@ -383,7 +391,8 @@ var unpluginFactory = (options) => ({
383
391
  try {
384
392
  const caddy2 = new CaddyInstant();
385
393
  caddy2.run(source, target, {
386
- base
394
+ base,
395
+ showCaddyLog: options.showCaddyLog
387
396
  }).then((stop) => {
388
397
  const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
389
398
  consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
@@ -392,6 +401,8 @@ var unpluginFactory = (options) => ({
392
401
  server.close();
393
402
  import_node_process3.default.exit();
394
403
  });
404
+ }).catch((e) => {
405
+ throw e;
395
406
  });
396
407
  } catch (e) {
397
408
  consola.error(e);
@@ -401,8 +412,11 @@ var unpluginFactory = (options) => ({
401
412
  },
402
413
  webpack(compiler) {
403
414
  const {
415
+ enable = true,
404
416
  target = ""
405
417
  } = options;
418
+ if (!enable)
419
+ return;
406
420
  if (!target) {
407
421
  consola.fail("please provide target");
408
422
  return;
@@ -413,7 +427,9 @@ var unpluginFactory = (options) => ({
413
427
  if (caddy)
414
428
  return;
415
429
  caddy = new CaddyInstant();
416
- caddy.run(source, target).then((stop) => {
430
+ caddy.run(source, target, {
431
+ showCaddyLog: options.showCaddyLog
432
+ }).then((stop) => {
417
433
  const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
418
434
  compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
419
435
  if (stats.hasErrors())
package/dist/rollup.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-AJ47BPUG.js";
3
+ } from "./chunk-WUSTJHAZ.js";
4
4
  import "./chunk-3HKPYCSE.js";
5
5
 
6
6
  // src/rollup.ts
package/dist/types.d.cts CHANGED
@@ -1,5 +1,7 @@
1
1
  interface Options {
2
+ enable?: boolean;
2
3
  target: string;
4
+ showCaddyLog?: boolean;
3
5
  }
4
6
 
5
7
  export { Options };
package/dist/types.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  interface Options {
2
+ enable?: boolean;
2
3
  target: string;
4
+ showCaddyLog?: boolean;
3
5
  }
4
6
 
5
7
  export { Options };
package/dist/vite.cjs CHANGED
@@ -314,7 +314,8 @@ var CaddyInstant = class {
314
314
  source = source.replace("0.0.0.0", "127.0.0.1").replace("localhost", "127.0.0.1");
315
315
  const {
316
316
  restore = true,
317
- base = "/"
317
+ base = "/",
318
+ showCaddyLog = false
318
319
  } = options || {};
319
320
  if (!this.inited)
320
321
  await this.init();
@@ -330,9 +331,13 @@ var CaddyInstant = class {
330
331
  return reject(err);
331
332
  });
332
333
  child.stderr.on("data", (data) => {
333
- if (data.toString().includes("Error")) {
334
- child.kill();
335
- return reject(data.toString());
334
+ const lines = data.toString().split("\n").map((line) => line.trim());
335
+ for (const line of lines) {
336
+ showCaddyLog && line && console.info(line);
337
+ if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
338
+ consola.error(line);
339
+ return reject(line);
340
+ }
336
341
  }
337
342
  });
338
343
  child.stdout.on("data", (_data) => {
@@ -363,8 +368,11 @@ var unpluginFactory = (options) => ({
363
368
  },
364
369
  configureServer(server) {
365
370
  const {
371
+ enable = true,
366
372
  target = ""
367
373
  } = options;
374
+ if (!enable)
375
+ return;
368
376
  if (!target) {
369
377
  consola.fail("please provide target");
370
378
  return;
@@ -383,7 +391,8 @@ var unpluginFactory = (options) => ({
383
391
  try {
384
392
  const caddy2 = new CaddyInstant();
385
393
  caddy2.run(source, target, {
386
- base
394
+ base,
395
+ showCaddyLog: options.showCaddyLog
387
396
  }).then((stop) => {
388
397
  const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
389
398
  consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
@@ -392,6 +401,8 @@ var unpluginFactory = (options) => ({
392
401
  server.close();
393
402
  import_node_process3.default.exit();
394
403
  });
404
+ }).catch((e) => {
405
+ throw e;
395
406
  });
396
407
  } catch (e) {
397
408
  consola.error(e);
@@ -401,8 +412,11 @@ var unpluginFactory = (options) => ({
401
412
  },
402
413
  webpack(compiler) {
403
414
  const {
415
+ enable = true,
404
416
  target = ""
405
417
  } = options;
418
+ if (!enable)
419
+ return;
406
420
  if (!target) {
407
421
  consola.fail("please provide target");
408
422
  return;
@@ -413,7 +427,9 @@ var unpluginFactory = (options) => ({
413
427
  if (caddy)
414
428
  return;
415
429
  caddy = new CaddyInstant();
416
- caddy.run(source, target).then((stop) => {
430
+ caddy.run(source, target, {
431
+ showCaddyLog: options.showCaddyLog
432
+ }).then((stop) => {
417
433
  const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
418
434
  compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
419
435
  if (stats.hasErrors())
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  vite_default
3
- } from "./chunk-FD66DR3R.js";
4
- import "./chunk-AJ47BPUG.js";
3
+ } from "./chunk-YP6CZ57A.js";
4
+ import "./chunk-WUSTJHAZ.js";
5
5
  import "./chunk-3HKPYCSE.js";
6
6
  export {
7
7
  vite_default as default
package/dist/webpack.cjs CHANGED
@@ -314,7 +314,8 @@ var CaddyInstant = class {
314
314
  source = source.replace("0.0.0.0", "127.0.0.1").replace("localhost", "127.0.0.1");
315
315
  const {
316
316
  restore = true,
317
- base = "/"
317
+ base = "/",
318
+ showCaddyLog = false
318
319
  } = options || {};
319
320
  if (!this.inited)
320
321
  await this.init();
@@ -330,9 +331,13 @@ var CaddyInstant = class {
330
331
  return reject(err);
331
332
  });
332
333
  child.stderr.on("data", (data) => {
333
- if (data.toString().includes("Error")) {
334
- child.kill();
335
- return reject(data.toString());
334
+ const lines = data.toString().split("\n").map((line) => line.trim());
335
+ for (const line of lines) {
336
+ showCaddyLog && line && console.info(line);
337
+ if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
338
+ consola.error(line);
339
+ return reject(line);
340
+ }
336
341
  }
337
342
  });
338
343
  child.stdout.on("data", (_data) => {
@@ -363,8 +368,11 @@ var unpluginFactory = (options) => ({
363
368
  },
364
369
  configureServer(server) {
365
370
  const {
371
+ enable = true,
366
372
  target = ""
367
373
  } = options;
374
+ if (!enable)
375
+ return;
368
376
  if (!target) {
369
377
  consola.fail("please provide target");
370
378
  return;
@@ -383,7 +391,8 @@ var unpluginFactory = (options) => ({
383
391
  try {
384
392
  const caddy2 = new CaddyInstant();
385
393
  caddy2.run(source, target, {
386
- base
394
+ base,
395
+ showCaddyLog: options.showCaddyLog
387
396
  }).then((stop) => {
388
397
  const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
389
398
  consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
@@ -392,6 +401,8 @@ var unpluginFactory = (options) => ({
392
401
  server.close();
393
402
  import_node_process3.default.exit();
394
403
  });
404
+ }).catch((e) => {
405
+ throw e;
395
406
  });
396
407
  } catch (e) {
397
408
  consola.error(e);
@@ -401,8 +412,11 @@ var unpluginFactory = (options) => ({
401
412
  },
402
413
  webpack(compiler) {
403
414
  const {
415
+ enable = true,
404
416
  target = ""
405
417
  } = options;
418
+ if (!enable)
419
+ return;
406
420
  if (!target) {
407
421
  consola.fail("please provide target");
408
422
  return;
@@ -413,7 +427,9 @@ var unpluginFactory = (options) => ({
413
427
  if (caddy)
414
428
  return;
415
429
  caddy = new CaddyInstant();
416
- caddy.run(source, target).then((stop) => {
430
+ caddy.run(source, target, {
431
+ showCaddyLog: options.showCaddyLog
432
+ }).then((stop) => {
417
433
  const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
418
434
  compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
419
435
  if (stats.hasErrors())
package/dist/webpack.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  webpack_default
3
- } from "./chunk-J2XKEZPC.js";
4
- import "./chunk-AJ47BPUG.js";
3
+ } from "./chunk-ARWX57QE.js";
4
+ import "./chunk-WUSTJHAZ.js";
5
5
  import "./chunk-3HKPYCSE.js";
6
6
  export {
7
7
  webpack_default as default
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.10",
4
+ "version": "0.0.12",
5
5
  "packageManager": "pnpm@8.6.12",
6
6
  "description": "",
7
7
  "license": "MIT",
@@ -81,6 +81,7 @@ function testCaddy() {
81
81
  interface RunOptions {
82
82
  restore: boolean
83
83
  base: string
84
+ showCaddyLog: boolean
84
85
  }
85
86
 
86
87
  export class CaddyInstant {
@@ -161,6 +162,7 @@ export class CaddyInstant {
161
162
  const {
162
163
  restore = true,
163
164
  base = '/',
165
+ showCaddyLog = false,
164
166
  } = options || {}
165
167
 
166
168
  if (!this.inited)
@@ -185,9 +187,16 @@ export class CaddyInstant {
185
187
  })
186
188
 
187
189
  child.stderr.on('data', (data) => {
188
- if ((data.toString() as string).includes('Error')) {
189
- child.kill()
190
- return reject(data.toString())
190
+ const lines = (data.toString() as string).split('\n').map(line => line.trim())
191
+ for (const line of lines) {
192
+ // caddy log
193
+ // eslint-disable-next-line no-console
194
+ showCaddyLog && line && console.info(line)
195
+ if (line.includes('Error:') || (line && JSON.parse(line).level === 'error')) {
196
+ consola.error(line)
197
+ // child.kill()
198
+ return reject(line)
199
+ }
191
200
  }
192
201
  })
193
202
 
package/src/index.ts CHANGED
@@ -20,8 +20,11 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
20
20
  },
21
21
  configureServer(server) {
22
22
  const {
23
+ enable = true,
23
24
  target = '',
24
25
  } = options
26
+ if (!enable)
27
+ return
25
28
  if (!target) {
26
29
  consola.fail('please provide target')
27
30
  return
@@ -40,6 +43,7 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
40
43
  const caddy = new CaddyInstant()
41
44
  caddy.run(source, target, {
42
45
  base,
46
+ showCaddyLog: options.showCaddyLog,
43
47
  }).then((stop) => {
44
48
  const colorUrl = (url: string) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`))
45
49
  consola.success(` ${c.green('➜')} ${c.bold('run caddy reverse proxy success')}: ${colorUrl(`https://${target}${base}`)}`)
@@ -49,6 +53,8 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
49
53
  server.close()
50
54
  process.exit()
51
55
  })
56
+ }).catch((e) => {
57
+ throw e
52
58
  })
53
59
  }
54
60
  catch (e) {
@@ -59,8 +65,11 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
59
65
  },
60
66
  webpack(compiler) {
61
67
  const {
68
+ enable = true,
62
69
  target = '',
63
70
  } = options
71
+ if (!enable)
72
+ return
64
73
  if (!target) {
65
74
  consola.fail('please provide target')
66
75
  return
@@ -75,7 +84,9 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
75
84
 
76
85
  caddy = new CaddyInstant()
77
86
 
78
- caddy.run(source, target).then((stop) => {
87
+ caddy.run(source, target, {
88
+ showCaddyLog: options.showCaddyLog,
89
+ }).then((stop) => {
79
90
  const colorUrl = (url: string) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`))
80
91
 
81
92
  compiler.hooks.done.tap('unplugin-https-reverse-proxy', (stats) => {
package/src/types.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export interface Options {
2
2
  // define your plugin options here
3
+ enable?: boolean
3
4
  target: string
5
+ showCaddyLog?: boolean
4
6
  }