unplugin-https-reverse-proxy 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -73,4 +73,15 @@ module.exports = {
73
73
  }
74
74
  ```
75
75
 
76
- <br>
76
+ <br></details>
77
+
78
+ ## Usage
79
+
80
+ ```bash
81
+ # macOS
82
+ sudo -E npm run dev # your dev script
83
+
84
+ # windows
85
+ # use powershell as administrator
86
+ npm run dev # your dev script
87
+ ```
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-QYHKWM3K.js";
3
+ } from "./chunk-FTJKGYCT.js";
4
4
 
5
5
  // src/vite.ts
6
6
  import { createVitePlugin } from "unplugin";
@@ -8,7 +8,9 @@ import { platform } from "os";
8
8
  import process2 from "process";
9
9
  import { chmodSync, createWriteStream, existsSync, unlinkSync } from "fs";
10
10
  import { spawn } from "child_process";
11
- import got from "got";
11
+ import { got } from "got-cjs";
12
+ import { HttpProxyAgent } from "http-proxy-agent";
13
+ import { HttpsProxyAgent } from "https-proxy-agent";
12
14
  import * as hostile from "hostile";
13
15
  import kill from "kill-port";
14
16
 
@@ -129,6 +131,27 @@ var supportList = [
129
131
  }
130
132
  ];
131
133
 
134
+ // src/caddy/utils.ts
135
+ import { createServer } from "net";
136
+ function tryPort(port) {
137
+ return new Promise((resolve, reject) => {
138
+ try {
139
+ const server = createServer().listen(port);
140
+ server.on("listening", () => {
141
+ server.close();
142
+ resolve(false);
143
+ });
144
+ server.on("error", (err) => {
145
+ if (err.code === "EADDRINUSE")
146
+ resolve(true);
147
+ server.close();
148
+ });
149
+ } catch (e) {
150
+ resolve(true);
151
+ }
152
+ });
153
+ }
154
+
132
155
  // src/caddy/index.ts
133
156
  async function download() {
134
157
  if (await testCaddy())
@@ -144,7 +167,16 @@ async function download() {
144
167
  return reject(new Error("not support"));
145
168
  const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}`;
146
169
  existsSync(caddyPath) && unlinkSync(caddyPath);
147
- got.stream(dowmloadLink).pipe(file).on("finish", () => {
170
+ const httpProxy = process2.env.HTTP_PROXY || process2.env.http_proxy;
171
+ const httpsProxy = process2.env.HTTPS_PROXY || process2.env.https_proxy;
172
+ const httpAgent = httpProxy ? new HttpProxyAgent(httpProxy) : void 0;
173
+ const httpsAgent = httpsProxy ? new HttpsProxyAgent(httpsProxy) : void 0;
174
+ got.stream(dowmloadLink, {
175
+ agent: {
176
+ http: httpAgent,
177
+ https: httpsAgent
178
+ }
179
+ }).pipe(file).on("finish", () => {
148
180
  if (process2.platform === "win32")
149
181
  return resolve(caddyPath);
150
182
  chmodSync(caddyPath, 493);
@@ -241,7 +273,8 @@ var CaddyInstant = class {
241
273
  await this.init();
242
274
  if (!await this.updateHost(source.split(":")[0], target.split(":")[0]))
243
275
  throw new Error("update host failed");
244
- await kill(443, "tcp");
276
+ if (await tryPort(443))
277
+ await kill(443, "tcp");
245
278
  return new Promise((resolve, reject) => {
246
279
  const child = spawn("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
247
280
  child.on("error", (err) => {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-QYHKWM3K.js";
3
+ } from "./chunk-FTJKGYCT.js";
4
4
 
5
5
  // src/webpack.ts
6
6
  import { createWebpackPlugin } from "unplugin";
package/dist/esbuild.cjs CHANGED
@@ -45,7 +45,9 @@ var import_node_os = require("os");
45
45
  var import_node_process2 = __toESM(require("process"), 1);
46
46
  var import_node_fs = require("fs");
47
47
  var import_node_child_process = require("child_process");
48
- var import_got = __toESM(require("got"), 1);
48
+ var import_got_cjs = require("got-cjs");
49
+ var import_http_proxy_agent = require("http-proxy-agent");
50
+ var import_https_proxy_agent = require("https-proxy-agent");
49
51
  var hostile = __toESM(require("hostile"), 1);
50
52
  var import_kill_port = __toESM(require("kill-port"), 1);
51
53
 
@@ -166,6 +168,27 @@ var supportList = [
166
168
  }
167
169
  ];
168
170
 
171
+ // src/caddy/utils.ts
172
+ var import_node_net = require("net");
173
+ function tryPort(port) {
174
+ return new Promise((resolve, reject) => {
175
+ try {
176
+ const server = (0, import_node_net.createServer)().listen(port);
177
+ server.on("listening", () => {
178
+ server.close();
179
+ resolve(false);
180
+ });
181
+ server.on("error", (err) => {
182
+ if (err.code === "EADDRINUSE")
183
+ resolve(true);
184
+ server.close();
185
+ });
186
+ } catch (e) {
187
+ resolve(true);
188
+ }
189
+ });
190
+ }
191
+
169
192
  // src/caddy/index.ts
170
193
  async function download() {
171
194
  if (await testCaddy())
@@ -181,7 +204,16 @@ async function download() {
181
204
  return reject(new Error("not support"));
182
205
  const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}`;
183
206
  (0, import_node_fs.existsSync)(caddyPath) && (0, import_node_fs.unlinkSync)(caddyPath);
184
- import_got.default.stream(dowmloadLink).pipe(file).on("finish", () => {
207
+ const httpProxy = import_node_process2.default.env.HTTP_PROXY || import_node_process2.default.env.http_proxy;
208
+ const httpsProxy = import_node_process2.default.env.HTTPS_PROXY || import_node_process2.default.env.https_proxy;
209
+ const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
210
+ const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
211
+ import_got_cjs.got.stream(dowmloadLink, {
212
+ agent: {
213
+ http: httpAgent,
214
+ https: httpsAgent
215
+ }
216
+ }).pipe(file).on("finish", () => {
185
217
  if (import_node_process2.default.platform === "win32")
186
218
  return resolve(caddyPath);
187
219
  (0, import_node_fs.chmodSync)(caddyPath, 493);
@@ -278,7 +310,8 @@ var CaddyInstant = class {
278
310
  await this.init();
279
311
  if (!await this.updateHost(source.split(":")[0], target.split(":")[0]))
280
312
  throw new Error("update host failed");
281
- await (0, import_kill_port.default)(443, "tcp");
313
+ if (await tryPort(443))
314
+ await (0, import_kill_port.default)(443, "tcp");
282
315
  return new Promise((resolve, reject) => {
283
316
  const child = (0, import_node_child_process.spawn)("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
284
317
  child.on("error", (err) => {
package/dist/esbuild.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-QYHKWM3K.js";
3
+ } from "./chunk-FTJKGYCT.js";
4
4
 
5
5
  // src/esbuild.ts
6
6
  import { createEsbuildPlugin } from "unplugin";
package/dist/index.cjs CHANGED
@@ -44,7 +44,9 @@ var import_node_os = require("os");
44
44
  var import_node_process2 = __toESM(require("process"), 1);
45
45
  var import_node_fs = require("fs");
46
46
  var import_node_child_process = require("child_process");
47
- var import_got = __toESM(require("got"), 1);
47
+ var import_got_cjs = require("got-cjs");
48
+ var import_http_proxy_agent = require("http-proxy-agent");
49
+ var import_https_proxy_agent = require("https-proxy-agent");
48
50
  var hostile = __toESM(require("hostile"), 1);
49
51
  var import_kill_port = __toESM(require("kill-port"), 1);
50
52
 
@@ -165,6 +167,27 @@ var supportList = [
165
167
  }
166
168
  ];
167
169
 
170
+ // src/caddy/utils.ts
171
+ var import_node_net = require("net");
172
+ function tryPort(port) {
173
+ return new Promise((resolve, reject) => {
174
+ try {
175
+ const server = (0, import_node_net.createServer)().listen(port);
176
+ server.on("listening", () => {
177
+ server.close();
178
+ resolve(false);
179
+ });
180
+ server.on("error", (err) => {
181
+ if (err.code === "EADDRINUSE")
182
+ resolve(true);
183
+ server.close();
184
+ });
185
+ } catch (e) {
186
+ resolve(true);
187
+ }
188
+ });
189
+ }
190
+
168
191
  // src/caddy/index.ts
169
192
  async function download() {
170
193
  if (await testCaddy())
@@ -180,7 +203,16 @@ async function download() {
180
203
  return reject(new Error("not support"));
181
204
  const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}`;
182
205
  (0, import_node_fs.existsSync)(caddyPath) && (0, import_node_fs.unlinkSync)(caddyPath);
183
- import_got.default.stream(dowmloadLink).pipe(file).on("finish", () => {
206
+ const httpProxy = import_node_process2.default.env.HTTP_PROXY || import_node_process2.default.env.http_proxy;
207
+ const httpsProxy = import_node_process2.default.env.HTTPS_PROXY || import_node_process2.default.env.https_proxy;
208
+ const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
209
+ const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
210
+ import_got_cjs.got.stream(dowmloadLink, {
211
+ agent: {
212
+ http: httpAgent,
213
+ https: httpsAgent
214
+ }
215
+ }).pipe(file).on("finish", () => {
184
216
  if (import_node_process2.default.platform === "win32")
185
217
  return resolve(caddyPath);
186
218
  (0, import_node_fs.chmodSync)(caddyPath, 493);
@@ -277,7 +309,8 @@ var CaddyInstant = class {
277
309
  await this.init();
278
310
  if (!await this.updateHost(source.split(":")[0], target.split(":")[0]))
279
311
  throw new Error("update host failed");
280
- await (0, import_kill_port.default)(443, "tcp");
312
+ if (await tryPort(443))
313
+ await (0, import_kill_port.default)(443, "tcp");
281
314
  return new Promise((resolve, reject) => {
282
315
  const child = (0, import_node_child_process.spawn)("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
283
316
  child.on("error", (err) => {
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  src_default,
3
3
  unplugin,
4
4
  unpluginFactory
5
- } from "./chunk-QYHKWM3K.js";
5
+ } from "./chunk-FTJKGYCT.js";
6
6
  export {
7
7
  src_default as default,
8
8
  unplugin,
package/dist/nuxt.cjs CHANGED
@@ -48,7 +48,9 @@ var import_node_os = require("os");
48
48
  var import_node_process2 = __toESM(require("process"), 1);
49
49
  var import_node_fs = require("fs");
50
50
  var import_node_child_process = require("child_process");
51
- var import_got = __toESM(require("got"), 1);
51
+ var import_got_cjs = require("got-cjs");
52
+ var import_http_proxy_agent = require("http-proxy-agent");
53
+ var import_https_proxy_agent = require("https-proxy-agent");
52
54
  var hostile = __toESM(require("hostile"), 1);
53
55
  var import_kill_port = __toESM(require("kill-port"), 1);
54
56
 
@@ -169,6 +171,27 @@ var supportList = [
169
171
  }
170
172
  ];
171
173
 
174
+ // src/caddy/utils.ts
175
+ var import_node_net = require("net");
176
+ function tryPort(port) {
177
+ return new Promise((resolve, reject) => {
178
+ try {
179
+ const server = (0, import_node_net.createServer)().listen(port);
180
+ server.on("listening", () => {
181
+ server.close();
182
+ resolve(false);
183
+ });
184
+ server.on("error", (err) => {
185
+ if (err.code === "EADDRINUSE")
186
+ resolve(true);
187
+ server.close();
188
+ });
189
+ } catch (e) {
190
+ resolve(true);
191
+ }
192
+ });
193
+ }
194
+
172
195
  // src/caddy/index.ts
173
196
  async function download() {
174
197
  if (await testCaddy())
@@ -184,7 +207,16 @@ async function download() {
184
207
  return reject(new Error("not support"));
185
208
  const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}`;
186
209
  (0, import_node_fs.existsSync)(caddyPath) && (0, import_node_fs.unlinkSync)(caddyPath);
187
- import_got.default.stream(dowmloadLink).pipe(file).on("finish", () => {
210
+ const httpProxy = import_node_process2.default.env.HTTP_PROXY || import_node_process2.default.env.http_proxy;
211
+ const httpsProxy = import_node_process2.default.env.HTTPS_PROXY || import_node_process2.default.env.https_proxy;
212
+ const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
213
+ const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
214
+ import_got_cjs.got.stream(dowmloadLink, {
215
+ agent: {
216
+ http: httpAgent,
217
+ https: httpsAgent
218
+ }
219
+ }).pipe(file).on("finish", () => {
188
220
  if (import_node_process2.default.platform === "win32")
189
221
  return resolve(caddyPath);
190
222
  (0, import_node_fs.chmodSync)(caddyPath, 493);
@@ -281,7 +313,8 @@ var CaddyInstant = class {
281
313
  await this.init();
282
314
  if (!await this.updateHost(source.split(":")[0], target.split(":")[0]))
283
315
  throw new Error("update host failed");
284
- await (0, import_kill_port.default)(443, "tcp");
316
+ if (await tryPort(443))
317
+ await (0, import_kill_port.default)(443, "tcp");
285
318
  return new Promise((resolve, reject) => {
286
319
  const child = (0, import_node_child_process.spawn)("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
287
320
  child.on("error", (err) => {
package/dist/nuxt.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  vite_default
3
- } from "./chunk-XWZYGFLS.js";
3
+ } from "./chunk-AIZ6VX2O.js";
4
4
  import {
5
5
  webpack_default
6
- } from "./chunk-TIR4PYKX.js";
7
- import "./chunk-QYHKWM3K.js";
6
+ } from "./chunk-TFGTJLXH.js";
7
+ import "./chunk-FTJKGYCT.js";
8
8
 
9
9
  // src/nuxt.ts
10
10
  import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
package/dist/rollup.cjs CHANGED
@@ -45,7 +45,9 @@ var import_node_os = require("os");
45
45
  var import_node_process2 = __toESM(require("process"), 1);
46
46
  var import_node_fs = require("fs");
47
47
  var import_node_child_process = require("child_process");
48
- var import_got = __toESM(require("got"), 1);
48
+ var import_got_cjs = require("got-cjs");
49
+ var import_http_proxy_agent = require("http-proxy-agent");
50
+ var import_https_proxy_agent = require("https-proxy-agent");
49
51
  var hostile = __toESM(require("hostile"), 1);
50
52
  var import_kill_port = __toESM(require("kill-port"), 1);
51
53
 
@@ -166,6 +168,27 @@ var supportList = [
166
168
  }
167
169
  ];
168
170
 
171
+ // src/caddy/utils.ts
172
+ var import_node_net = require("net");
173
+ function tryPort(port) {
174
+ return new Promise((resolve, reject) => {
175
+ try {
176
+ const server = (0, import_node_net.createServer)().listen(port);
177
+ server.on("listening", () => {
178
+ server.close();
179
+ resolve(false);
180
+ });
181
+ server.on("error", (err) => {
182
+ if (err.code === "EADDRINUSE")
183
+ resolve(true);
184
+ server.close();
185
+ });
186
+ } catch (e) {
187
+ resolve(true);
188
+ }
189
+ });
190
+ }
191
+
169
192
  // src/caddy/index.ts
170
193
  async function download() {
171
194
  if (await testCaddy())
@@ -181,7 +204,16 @@ async function download() {
181
204
  return reject(new Error("not support"));
182
205
  const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}`;
183
206
  (0, import_node_fs.existsSync)(caddyPath) && (0, import_node_fs.unlinkSync)(caddyPath);
184
- import_got.default.stream(dowmloadLink).pipe(file).on("finish", () => {
207
+ const httpProxy = import_node_process2.default.env.HTTP_PROXY || import_node_process2.default.env.http_proxy;
208
+ const httpsProxy = import_node_process2.default.env.HTTPS_PROXY || import_node_process2.default.env.https_proxy;
209
+ const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
210
+ const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
211
+ import_got_cjs.got.stream(dowmloadLink, {
212
+ agent: {
213
+ http: httpAgent,
214
+ https: httpsAgent
215
+ }
216
+ }).pipe(file).on("finish", () => {
185
217
  if (import_node_process2.default.platform === "win32")
186
218
  return resolve(caddyPath);
187
219
  (0, import_node_fs.chmodSync)(caddyPath, 493);
@@ -278,7 +310,8 @@ var CaddyInstant = class {
278
310
  await this.init();
279
311
  if (!await this.updateHost(source.split(":")[0], target.split(":")[0]))
280
312
  throw new Error("update host failed");
281
- await (0, import_kill_port.default)(443, "tcp");
313
+ if (await tryPort(443))
314
+ await (0, import_kill_port.default)(443, "tcp");
282
315
  return new Promise((resolve, reject) => {
283
316
  const child = (0, import_node_child_process.spawn)("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
284
317
  child.on("error", (err) => {
package/dist/rollup.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-QYHKWM3K.js";
3
+ } from "./chunk-FTJKGYCT.js";
4
4
 
5
5
  // src/rollup.ts
6
6
  import { createRollupPlugin } from "unplugin";
package/dist/vite.cjs CHANGED
@@ -45,7 +45,9 @@ var import_node_os = require("os");
45
45
  var import_node_process2 = __toESM(require("process"), 1);
46
46
  var import_node_fs = require("fs");
47
47
  var import_node_child_process = require("child_process");
48
- var import_got = __toESM(require("got"), 1);
48
+ var import_got_cjs = require("got-cjs");
49
+ var import_http_proxy_agent = require("http-proxy-agent");
50
+ var import_https_proxy_agent = require("https-proxy-agent");
49
51
  var hostile = __toESM(require("hostile"), 1);
50
52
  var import_kill_port = __toESM(require("kill-port"), 1);
51
53
 
@@ -166,6 +168,27 @@ var supportList = [
166
168
  }
167
169
  ];
168
170
 
171
+ // src/caddy/utils.ts
172
+ var import_node_net = require("net");
173
+ function tryPort(port) {
174
+ return new Promise((resolve, reject) => {
175
+ try {
176
+ const server = (0, import_node_net.createServer)().listen(port);
177
+ server.on("listening", () => {
178
+ server.close();
179
+ resolve(false);
180
+ });
181
+ server.on("error", (err) => {
182
+ if (err.code === "EADDRINUSE")
183
+ resolve(true);
184
+ server.close();
185
+ });
186
+ } catch (e) {
187
+ resolve(true);
188
+ }
189
+ });
190
+ }
191
+
169
192
  // src/caddy/index.ts
170
193
  async function download() {
171
194
  if (await testCaddy())
@@ -181,7 +204,16 @@ async function download() {
181
204
  return reject(new Error("not support"));
182
205
  const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}`;
183
206
  (0, import_node_fs.existsSync)(caddyPath) && (0, import_node_fs.unlinkSync)(caddyPath);
184
- import_got.default.stream(dowmloadLink).pipe(file).on("finish", () => {
207
+ const httpProxy = import_node_process2.default.env.HTTP_PROXY || import_node_process2.default.env.http_proxy;
208
+ const httpsProxy = import_node_process2.default.env.HTTPS_PROXY || import_node_process2.default.env.https_proxy;
209
+ const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
210
+ const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
211
+ import_got_cjs.got.stream(dowmloadLink, {
212
+ agent: {
213
+ http: httpAgent,
214
+ https: httpsAgent
215
+ }
216
+ }).pipe(file).on("finish", () => {
185
217
  if (import_node_process2.default.platform === "win32")
186
218
  return resolve(caddyPath);
187
219
  (0, import_node_fs.chmodSync)(caddyPath, 493);
@@ -278,7 +310,8 @@ var CaddyInstant = class {
278
310
  await this.init();
279
311
  if (!await this.updateHost(source.split(":")[0], target.split(":")[0]))
280
312
  throw new Error("update host failed");
281
- await (0, import_kill_port.default)(443, "tcp");
313
+ if (await tryPort(443))
314
+ await (0, import_kill_port.default)(443, "tcp");
282
315
  return new Promise((resolve, reject) => {
283
316
  const child = (0, import_node_child_process.spawn)("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
284
317
  child.on("error", (err) => {
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  vite_default
3
- } from "./chunk-XWZYGFLS.js";
4
- import "./chunk-QYHKWM3K.js";
3
+ } from "./chunk-AIZ6VX2O.js";
4
+ import "./chunk-FTJKGYCT.js";
5
5
  export {
6
6
  vite_default as default
7
7
  };
package/dist/webpack.cjs CHANGED
@@ -45,7 +45,9 @@ var import_node_os = require("os");
45
45
  var import_node_process2 = __toESM(require("process"), 1);
46
46
  var import_node_fs = require("fs");
47
47
  var import_node_child_process = require("child_process");
48
- var import_got = __toESM(require("got"), 1);
48
+ var import_got_cjs = require("got-cjs");
49
+ var import_http_proxy_agent = require("http-proxy-agent");
50
+ var import_https_proxy_agent = require("https-proxy-agent");
49
51
  var hostile = __toESM(require("hostile"), 1);
50
52
  var import_kill_port = __toESM(require("kill-port"), 1);
51
53
 
@@ -166,6 +168,27 @@ var supportList = [
166
168
  }
167
169
  ];
168
170
 
171
+ // src/caddy/utils.ts
172
+ var import_node_net = require("net");
173
+ function tryPort(port) {
174
+ return new Promise((resolve, reject) => {
175
+ try {
176
+ const server = (0, import_node_net.createServer)().listen(port);
177
+ server.on("listening", () => {
178
+ server.close();
179
+ resolve(false);
180
+ });
181
+ server.on("error", (err) => {
182
+ if (err.code === "EADDRINUSE")
183
+ resolve(true);
184
+ server.close();
185
+ });
186
+ } catch (e) {
187
+ resolve(true);
188
+ }
189
+ });
190
+ }
191
+
169
192
  // src/caddy/index.ts
170
193
  async function download() {
171
194
  if (await testCaddy())
@@ -181,7 +204,16 @@ async function download() {
181
204
  return reject(new Error("not support"));
182
205
  const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}`;
183
206
  (0, import_node_fs.existsSync)(caddyPath) && (0, import_node_fs.unlinkSync)(caddyPath);
184
- import_got.default.stream(dowmloadLink).pipe(file).on("finish", () => {
207
+ const httpProxy = import_node_process2.default.env.HTTP_PROXY || import_node_process2.default.env.http_proxy;
208
+ const httpsProxy = import_node_process2.default.env.HTTPS_PROXY || import_node_process2.default.env.https_proxy;
209
+ const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
210
+ const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
211
+ import_got_cjs.got.stream(dowmloadLink, {
212
+ agent: {
213
+ http: httpAgent,
214
+ https: httpsAgent
215
+ }
216
+ }).pipe(file).on("finish", () => {
185
217
  if (import_node_process2.default.platform === "win32")
186
218
  return resolve(caddyPath);
187
219
  (0, import_node_fs.chmodSync)(caddyPath, 493);
@@ -278,7 +310,8 @@ var CaddyInstant = class {
278
310
  await this.init();
279
311
  if (!await this.updateHost(source.split(":")[0], target.split(":")[0]))
280
312
  throw new Error("update host failed");
281
- await (0, import_kill_port.default)(443, "tcp");
313
+ if (await tryPort(443))
314
+ await (0, import_kill_port.default)(443, "tcp");
282
315
  return new Promise((resolve, reject) => {
283
316
  const child = (0, import_node_child_process.spawn)("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
284
317
  child.on("error", (err) => {
package/dist/webpack.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  webpack_default
3
- } from "./chunk-TIR4PYKX.js";
4
- import "./chunk-QYHKWM3K.js";
3
+ } from "./chunk-TFGTJLXH.js";
4
+ import "./chunk-FTJKGYCT.js";
5
5
  export {
6
6
  webpack_default as default
7
7
  };
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.1",
4
+ "version": "0.0.2",
5
5
  "packageManager": "pnpm@8.6.12",
6
6
  "description": "",
7
7
  "license": "MIT",
@@ -101,8 +101,10 @@
101
101
  }
102
102
  },
103
103
  "dependencies": {
104
- "got": "^13.0.0",
104
+ "got-cjs": "^12.5.4",
105
105
  "hostile": "^1.3.3",
106
+ "http-proxy-agent": "^7.0.0",
107
+ "https-proxy-agent": "^7.0.2",
106
108
  "kill-port": "^2.0.1",
107
109
  "picocolors": "^1.0.0",
108
110
  "unplugin": "^1.4.0"
@@ -111,7 +113,6 @@
111
113
  "@antfu/eslint-config": "^0.40.2",
112
114
  "@nuxt/kit": "^3.6.5",
113
115
  "@nuxt/schema": "^3.6.5",
114
- "@types/got": "^9.6.12",
115
116
  "@types/hostile": "^1.3.3",
116
117
  "@types/kill-port": "^2.0.3",
117
118
  "@types/node": "^20.5.2",