unplugin-https-reverse-proxy 0.0.2 → 0.0.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/README.md +19 -0
- package/dist/{chunk-FTJKGYCT.js → chunk-BWNBY4RY.js} +29 -12
- package/dist/{chunk-AIZ6VX2O.js → chunk-CCEFFLWU.js} +1 -1
- package/dist/{chunk-TFGTJLXH.js → chunk-YJTJH7KX.js} +1 -1
- package/dist/esbuild.cjs +29 -12
- package/dist/esbuild.js +1 -1
- package/dist/index.cjs +29 -12
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +29 -12
- package/dist/nuxt.js +3 -3
- package/dist/rollup.cjs +29 -12
- package/dist/rollup.js +1 -1
- package/dist/vite.cjs +29 -12
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +29 -12
- package/dist/webpack.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -35,6 +35,15 @@ Example: [`playground/`](./playground/)
|
|
|
35
35
|
// webpack.config.js
|
|
36
36
|
module.exports = {
|
|
37
37
|
/* ... */
|
|
38
|
+
devServer: {
|
|
39
|
+
client: {
|
|
40
|
+
// ↓ for HMR
|
|
41
|
+
webSocketURL: {
|
|
42
|
+
protocol: 'wss',
|
|
43
|
+
port: 443,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
38
47
|
plugins: [
|
|
39
48
|
require('unplugin-https-reverse-proxy/webpack')({ /* options */ })
|
|
40
49
|
]
|
|
@@ -65,6 +74,15 @@ export default defineNuxtConfig({
|
|
|
65
74
|
```ts
|
|
66
75
|
// vue.config.js
|
|
67
76
|
module.exports = {
|
|
77
|
+
devServer: {
|
|
78
|
+
client: {
|
|
79
|
+
// ↓ for HMR
|
|
80
|
+
webSocketURL: {
|
|
81
|
+
protocol: 'wss',
|
|
82
|
+
port: 443,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
68
86
|
configureWebpack: {
|
|
69
87
|
plugins: [
|
|
70
88
|
require('unplugin-https-reverse-proxy/webpack')({ /* options */ }),
|
|
@@ -80,6 +98,7 @@ module.exports = {
|
|
|
80
98
|
```bash
|
|
81
99
|
# macOS
|
|
82
100
|
sudo -E npm run dev # your dev script
|
|
101
|
+
# ^ `-E` is important
|
|
83
102
|
|
|
84
103
|
# windows
|
|
85
104
|
# use powershell as administrator
|
|
@@ -18,7 +18,7 @@ import kill from "kill-port";
|
|
|
18
18
|
import { join } from "path";
|
|
19
19
|
import process from "process";
|
|
20
20
|
var TEMP_DIR = process.env.TEMP || process.env.TMPDIR || "/tmp";
|
|
21
|
-
var caddyPath = join(TEMP_DIR,
|
|
21
|
+
var caddyPath = join(TEMP_DIR, `caddy${process.platform === "win32" ? ".exe" : ""}`);
|
|
22
22
|
var caddyFilePath = join(TEMP_DIR, "CADDYFILE");
|
|
23
23
|
var supportList = [
|
|
24
24
|
{
|
|
@@ -191,12 +191,15 @@ function testCaddy() {
|
|
|
191
191
|
if (!existsSync(caddyPath))
|
|
192
192
|
return resolve(false);
|
|
193
193
|
chmodSync(caddyPath, 493);
|
|
194
|
-
const child = spawn("sudo", [caddyPath]);
|
|
194
|
+
const child = process2.platform === "win32" ? spawn(caddyPath, []) : spawn("sudo", [caddyPath]);
|
|
195
|
+
child.on("close", () => {
|
|
196
|
+
return resolve(true);
|
|
197
|
+
});
|
|
195
198
|
child.on("error", (err) => {
|
|
196
|
-
reject(err);
|
|
199
|
+
return reject(err);
|
|
197
200
|
});
|
|
198
201
|
child.stdout.on("data", (_data) => {
|
|
199
|
-
resolve(true);
|
|
202
|
+
return resolve(true);
|
|
200
203
|
});
|
|
201
204
|
});
|
|
202
205
|
}
|
|
@@ -265,8 +268,9 @@ var CaddyInstant = class {
|
|
|
265
268
|
* @returns
|
|
266
269
|
*/
|
|
267
270
|
async run(source, target, options) {
|
|
271
|
+
source = source.replace("0.0.0.0", "127.0.0.1").replace("localhost", "127.0.0.1");
|
|
268
272
|
const {
|
|
269
|
-
restore =
|
|
273
|
+
restore = true,
|
|
270
274
|
base = "/"
|
|
271
275
|
} = options || {};
|
|
272
276
|
if (!this.inited)
|
|
@@ -275,8 +279,10 @@ var CaddyInstant = class {
|
|
|
275
279
|
throw new Error("update host failed");
|
|
276
280
|
if (await tryPort(443))
|
|
277
281
|
await kill(443, "tcp");
|
|
282
|
+
if (process2.platform === "win32" && await tryPort(80))
|
|
283
|
+
await kill(80, "tcp");
|
|
278
284
|
return new Promise((resolve, reject) => {
|
|
279
|
-
const child = spawn("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
285
|
+
const child = process2.platform !== "win32" ? spawn("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]) : spawn(caddyPath, ["reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
280
286
|
child.on("error", (err) => {
|
|
281
287
|
return reject(err);
|
|
282
288
|
});
|
|
@@ -287,6 +293,7 @@ var CaddyInstant = class {
|
|
|
287
293
|
}
|
|
288
294
|
});
|
|
289
295
|
child.stdout.on("data", (_data) => {
|
|
296
|
+
console.log(_data.toString());
|
|
290
297
|
resolve(async () => {
|
|
291
298
|
if (!restore)
|
|
292
299
|
return;
|
|
@@ -304,8 +311,10 @@ var CaddyInstant = class {
|
|
|
304
311
|
|
|
305
312
|
// src/index.ts
|
|
306
313
|
var config;
|
|
314
|
+
var caddy;
|
|
307
315
|
var unpluginFactory = (options) => ({
|
|
308
316
|
name: "unplugin-https-reverse-proxy",
|
|
317
|
+
enforce: "post",
|
|
309
318
|
vite: {
|
|
310
319
|
configResolved(_config) {
|
|
311
320
|
config = _config;
|
|
@@ -328,8 +337,8 @@ var unpluginFactory = (options) => ({
|
|
|
328
337
|
}
|
|
329
338
|
const base = server.config.base || "/";
|
|
330
339
|
try {
|
|
331
|
-
const
|
|
332
|
-
|
|
340
|
+
const caddy2 = new CaddyInstant();
|
|
341
|
+
caddy2.run(source, target, {
|
|
333
342
|
base
|
|
334
343
|
}).then((stop) => {
|
|
335
344
|
const colorUrl = (url2) => c.green(url2.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
|
|
@@ -347,7 +356,6 @@ var unpluginFactory = (options) => ({
|
|
|
347
356
|
}
|
|
348
357
|
},
|
|
349
358
|
webpack(compiler) {
|
|
350
|
-
var _a, _b;
|
|
351
359
|
const {
|
|
352
360
|
target = ""
|
|
353
361
|
} = options;
|
|
@@ -355,16 +363,25 @@ var unpluginFactory = (options) => ({
|
|
|
355
363
|
console.log("please provide target");
|
|
356
364
|
return;
|
|
357
365
|
}
|
|
358
|
-
const source = `${((_a = compiler.options.devServer) == null ? void 0 : _a.host) || "127.0.0.1"}:${((_b = compiler.options.devServer) == null ? void 0 : _b.port) || "8080"}`;
|
|
359
366
|
try {
|
|
360
|
-
const
|
|
367
|
+
const devServer = compiler.options.devServer || process3.VUE_CLI_SERVICE.projectOptions.devServer;
|
|
368
|
+
const source = `${(devServer == null ? void 0 : devServer.host) || "127.0.0.1"}:${(devServer == null ? void 0 : devServer.port) || "8080"}`;
|
|
369
|
+
if (caddy)
|
|
370
|
+
return;
|
|
371
|
+
caddy = new CaddyInstant();
|
|
361
372
|
caddy.run(source, target).then((stop) => {
|
|
362
373
|
const colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
|
|
363
|
-
|
|
374
|
+
compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
|
|
375
|
+
if (stats.hasErrors())
|
|
376
|
+
return;
|
|
377
|
+
console.log(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
|
|
378
|
+
});
|
|
364
379
|
process3.on("SIGINT", async () => {
|
|
365
380
|
await stop();
|
|
366
381
|
process3.exit();
|
|
367
382
|
});
|
|
383
|
+
}).catch((e) => {
|
|
384
|
+
throw e;
|
|
368
385
|
});
|
|
369
386
|
} catch (e) {
|
|
370
387
|
console.error(e);
|
package/dist/esbuild.cjs
CHANGED
|
@@ -55,7 +55,7 @@ var import_kill_port = __toESM(require("kill-port"), 1);
|
|
|
55
55
|
var import_node_path = require("path");
|
|
56
56
|
var import_node_process = __toESM(require("process"), 1);
|
|
57
57
|
var TEMP_DIR = import_node_process.default.env.TEMP || import_node_process.default.env.TMPDIR || "/tmp";
|
|
58
|
-
var caddyPath = (0, import_node_path.join)(TEMP_DIR,
|
|
58
|
+
var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process.default.platform === "win32" ? ".exe" : ""}`);
|
|
59
59
|
var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
|
|
60
60
|
var supportList = [
|
|
61
61
|
{
|
|
@@ -228,12 +228,15 @@ function testCaddy() {
|
|
|
228
228
|
if (!(0, import_node_fs.existsSync)(caddyPath))
|
|
229
229
|
return resolve(false);
|
|
230
230
|
(0, import_node_fs.chmodSync)(caddyPath, 493);
|
|
231
|
-
const child = (0, import_node_child_process.spawn)("sudo", [caddyPath]);
|
|
231
|
+
const child = import_node_process2.default.platform === "win32" ? (0, import_node_child_process.spawn)(caddyPath, []) : (0, import_node_child_process.spawn)("sudo", [caddyPath]);
|
|
232
|
+
child.on("close", () => {
|
|
233
|
+
return resolve(true);
|
|
234
|
+
});
|
|
232
235
|
child.on("error", (err) => {
|
|
233
|
-
reject(err);
|
|
236
|
+
return reject(err);
|
|
234
237
|
});
|
|
235
238
|
child.stdout.on("data", (_data) => {
|
|
236
|
-
resolve(true);
|
|
239
|
+
return resolve(true);
|
|
237
240
|
});
|
|
238
241
|
});
|
|
239
242
|
}
|
|
@@ -302,8 +305,9 @@ var CaddyInstant = class {
|
|
|
302
305
|
* @returns
|
|
303
306
|
*/
|
|
304
307
|
async run(source, target, options) {
|
|
308
|
+
source = source.replace("0.0.0.0", "127.0.0.1").replace("localhost", "127.0.0.1");
|
|
305
309
|
const {
|
|
306
|
-
restore =
|
|
310
|
+
restore = true,
|
|
307
311
|
base = "/"
|
|
308
312
|
} = options || {};
|
|
309
313
|
if (!this.inited)
|
|
@@ -312,8 +316,10 @@ var CaddyInstant = class {
|
|
|
312
316
|
throw new Error("update host failed");
|
|
313
317
|
if (await tryPort(443))
|
|
314
318
|
await (0, import_kill_port.default)(443, "tcp");
|
|
319
|
+
if (import_node_process2.default.platform === "win32" && await tryPort(80))
|
|
320
|
+
await (0, import_kill_port.default)(80, "tcp");
|
|
315
321
|
return new Promise((resolve, reject) => {
|
|
316
|
-
const child = (0, import_node_child_process.spawn)("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
322
|
+
const child = import_node_process2.default.platform !== "win32" ? (0, import_node_child_process.spawn)("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]) : (0, import_node_child_process.spawn)(caddyPath, ["reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
317
323
|
child.on("error", (err) => {
|
|
318
324
|
return reject(err);
|
|
319
325
|
});
|
|
@@ -324,6 +330,7 @@ var CaddyInstant = class {
|
|
|
324
330
|
}
|
|
325
331
|
});
|
|
326
332
|
child.stdout.on("data", (_data) => {
|
|
333
|
+
console.log(_data.toString());
|
|
327
334
|
resolve(async () => {
|
|
328
335
|
if (!restore)
|
|
329
336
|
return;
|
|
@@ -341,8 +348,10 @@ var CaddyInstant = class {
|
|
|
341
348
|
|
|
342
349
|
// src/index.ts
|
|
343
350
|
var config;
|
|
351
|
+
var caddy;
|
|
344
352
|
var unpluginFactory = (options) => ({
|
|
345
353
|
name: "unplugin-https-reverse-proxy",
|
|
354
|
+
enforce: "post",
|
|
346
355
|
vite: {
|
|
347
356
|
configResolved(_config) {
|
|
348
357
|
config = _config;
|
|
@@ -365,8 +374,8 @@ var unpluginFactory = (options) => ({
|
|
|
365
374
|
}
|
|
366
375
|
const base = server.config.base || "/";
|
|
367
376
|
try {
|
|
368
|
-
const
|
|
369
|
-
|
|
377
|
+
const caddy2 = new CaddyInstant();
|
|
378
|
+
caddy2.run(source, target, {
|
|
370
379
|
base
|
|
371
380
|
}).then((stop) => {
|
|
372
381
|
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
@@ -384,7 +393,6 @@ var unpluginFactory = (options) => ({
|
|
|
384
393
|
}
|
|
385
394
|
},
|
|
386
395
|
webpack(compiler) {
|
|
387
|
-
var _a, _b;
|
|
388
396
|
const {
|
|
389
397
|
target = ""
|
|
390
398
|
} = options;
|
|
@@ -392,16 +400,25 @@ var unpluginFactory = (options) => ({
|
|
|
392
400
|
console.log("please provide target");
|
|
393
401
|
return;
|
|
394
402
|
}
|
|
395
|
-
const source = `${((_a = compiler.options.devServer) == null ? void 0 : _a.host) || "127.0.0.1"}:${((_b = compiler.options.devServer) == null ? void 0 : _b.port) || "8080"}`;
|
|
396
403
|
try {
|
|
397
|
-
const
|
|
404
|
+
const devServer = compiler.options.devServer || import_node_process3.default.VUE_CLI_SERVICE.projectOptions.devServer;
|
|
405
|
+
const source = `${(devServer == null ? void 0 : devServer.host) || "127.0.0.1"}:${(devServer == null ? void 0 : devServer.port) || "8080"}`;
|
|
406
|
+
if (caddy)
|
|
407
|
+
return;
|
|
408
|
+
caddy = new CaddyInstant();
|
|
398
409
|
caddy.run(source, target).then((stop) => {
|
|
399
410
|
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
400
|
-
|
|
411
|
+
compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
|
|
412
|
+
if (stats.hasErrors())
|
|
413
|
+
return;
|
|
414
|
+
console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
|
|
415
|
+
});
|
|
401
416
|
import_node_process3.default.on("SIGINT", async () => {
|
|
402
417
|
await stop();
|
|
403
418
|
import_node_process3.default.exit();
|
|
404
419
|
});
|
|
420
|
+
}).catch((e) => {
|
|
421
|
+
throw e;
|
|
405
422
|
});
|
|
406
423
|
} catch (e) {
|
|
407
424
|
console.error(e);
|
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -54,7 +54,7 @@ var import_kill_port = __toESM(require("kill-port"), 1);
|
|
|
54
54
|
var import_node_path = require("path");
|
|
55
55
|
var import_node_process = __toESM(require("process"), 1);
|
|
56
56
|
var TEMP_DIR = import_node_process.default.env.TEMP || import_node_process.default.env.TMPDIR || "/tmp";
|
|
57
|
-
var caddyPath = (0, import_node_path.join)(TEMP_DIR,
|
|
57
|
+
var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process.default.platform === "win32" ? ".exe" : ""}`);
|
|
58
58
|
var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
|
|
59
59
|
var supportList = [
|
|
60
60
|
{
|
|
@@ -227,12 +227,15 @@ function testCaddy() {
|
|
|
227
227
|
if (!(0, import_node_fs.existsSync)(caddyPath))
|
|
228
228
|
return resolve(false);
|
|
229
229
|
(0, import_node_fs.chmodSync)(caddyPath, 493);
|
|
230
|
-
const child = (0, import_node_child_process.spawn)("sudo", [caddyPath]);
|
|
230
|
+
const child = import_node_process2.default.platform === "win32" ? (0, import_node_child_process.spawn)(caddyPath, []) : (0, import_node_child_process.spawn)("sudo", [caddyPath]);
|
|
231
|
+
child.on("close", () => {
|
|
232
|
+
return resolve(true);
|
|
233
|
+
});
|
|
231
234
|
child.on("error", (err) => {
|
|
232
|
-
reject(err);
|
|
235
|
+
return reject(err);
|
|
233
236
|
});
|
|
234
237
|
child.stdout.on("data", (_data) => {
|
|
235
|
-
resolve(true);
|
|
238
|
+
return resolve(true);
|
|
236
239
|
});
|
|
237
240
|
});
|
|
238
241
|
}
|
|
@@ -301,8 +304,9 @@ var CaddyInstant = class {
|
|
|
301
304
|
* @returns
|
|
302
305
|
*/
|
|
303
306
|
async run(source, target, options) {
|
|
307
|
+
source = source.replace("0.0.0.0", "127.0.0.1").replace("localhost", "127.0.0.1");
|
|
304
308
|
const {
|
|
305
|
-
restore =
|
|
309
|
+
restore = true,
|
|
306
310
|
base = "/"
|
|
307
311
|
} = options || {};
|
|
308
312
|
if (!this.inited)
|
|
@@ -311,8 +315,10 @@ var CaddyInstant = class {
|
|
|
311
315
|
throw new Error("update host failed");
|
|
312
316
|
if (await tryPort(443))
|
|
313
317
|
await (0, import_kill_port.default)(443, "tcp");
|
|
318
|
+
if (import_node_process2.default.platform === "win32" && await tryPort(80))
|
|
319
|
+
await (0, import_kill_port.default)(80, "tcp");
|
|
314
320
|
return new Promise((resolve, reject) => {
|
|
315
|
-
const child = (0, import_node_child_process.spawn)("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
321
|
+
const child = import_node_process2.default.platform !== "win32" ? (0, import_node_child_process.spawn)("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]) : (0, import_node_child_process.spawn)(caddyPath, ["reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
316
322
|
child.on("error", (err) => {
|
|
317
323
|
return reject(err);
|
|
318
324
|
});
|
|
@@ -323,6 +329,7 @@ var CaddyInstant = class {
|
|
|
323
329
|
}
|
|
324
330
|
});
|
|
325
331
|
child.stdout.on("data", (_data) => {
|
|
332
|
+
console.log(_data.toString());
|
|
326
333
|
resolve(async () => {
|
|
327
334
|
if (!restore)
|
|
328
335
|
return;
|
|
@@ -340,8 +347,10 @@ var CaddyInstant = class {
|
|
|
340
347
|
|
|
341
348
|
// src/index.ts
|
|
342
349
|
var config;
|
|
350
|
+
var caddy;
|
|
343
351
|
var unpluginFactory = (options) => ({
|
|
344
352
|
name: "unplugin-https-reverse-proxy",
|
|
353
|
+
enforce: "post",
|
|
345
354
|
vite: {
|
|
346
355
|
configResolved(_config) {
|
|
347
356
|
config = _config;
|
|
@@ -364,8 +373,8 @@ var unpluginFactory = (options) => ({
|
|
|
364
373
|
}
|
|
365
374
|
const base = server.config.base || "/";
|
|
366
375
|
try {
|
|
367
|
-
const
|
|
368
|
-
|
|
376
|
+
const caddy2 = new CaddyInstant();
|
|
377
|
+
caddy2.run(source, target, {
|
|
369
378
|
base
|
|
370
379
|
}).then((stop) => {
|
|
371
380
|
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
@@ -383,7 +392,6 @@ var unpluginFactory = (options) => ({
|
|
|
383
392
|
}
|
|
384
393
|
},
|
|
385
394
|
webpack(compiler) {
|
|
386
|
-
var _a, _b;
|
|
387
395
|
const {
|
|
388
396
|
target = ""
|
|
389
397
|
} = options;
|
|
@@ -391,16 +399,25 @@ var unpluginFactory = (options) => ({
|
|
|
391
399
|
console.log("please provide target");
|
|
392
400
|
return;
|
|
393
401
|
}
|
|
394
|
-
const source = `${((_a = compiler.options.devServer) == null ? void 0 : _a.host) || "127.0.0.1"}:${((_b = compiler.options.devServer) == null ? void 0 : _b.port) || "8080"}`;
|
|
395
402
|
try {
|
|
396
|
-
const
|
|
403
|
+
const devServer = compiler.options.devServer || import_node_process3.default.VUE_CLI_SERVICE.projectOptions.devServer;
|
|
404
|
+
const source = `${(devServer == null ? void 0 : devServer.host) || "127.0.0.1"}:${(devServer == null ? void 0 : devServer.port) || "8080"}`;
|
|
405
|
+
if (caddy)
|
|
406
|
+
return;
|
|
407
|
+
caddy = new CaddyInstant();
|
|
397
408
|
caddy.run(source, target).then((stop) => {
|
|
398
409
|
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
399
|
-
|
|
410
|
+
compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
|
|
411
|
+
if (stats.hasErrors())
|
|
412
|
+
return;
|
|
413
|
+
console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
|
|
414
|
+
});
|
|
400
415
|
import_node_process3.default.on("SIGINT", async () => {
|
|
401
416
|
await stop();
|
|
402
417
|
import_node_process3.default.exit();
|
|
403
418
|
});
|
|
419
|
+
}).catch((e) => {
|
|
420
|
+
throw e;
|
|
404
421
|
});
|
|
405
422
|
} catch (e) {
|
|
406
423
|
console.error(e);
|
package/dist/index.js
CHANGED
package/dist/nuxt.cjs
CHANGED
|
@@ -58,7 +58,7 @@ var import_kill_port = __toESM(require("kill-port"), 1);
|
|
|
58
58
|
var import_node_path = require("path");
|
|
59
59
|
var import_node_process = __toESM(require("process"), 1);
|
|
60
60
|
var TEMP_DIR = import_node_process.default.env.TEMP || import_node_process.default.env.TMPDIR || "/tmp";
|
|
61
|
-
var caddyPath = (0, import_node_path.join)(TEMP_DIR,
|
|
61
|
+
var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process.default.platform === "win32" ? ".exe" : ""}`);
|
|
62
62
|
var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
|
|
63
63
|
var supportList = [
|
|
64
64
|
{
|
|
@@ -231,12 +231,15 @@ function testCaddy() {
|
|
|
231
231
|
if (!(0, import_node_fs.existsSync)(caddyPath))
|
|
232
232
|
return resolve(false);
|
|
233
233
|
(0, import_node_fs.chmodSync)(caddyPath, 493);
|
|
234
|
-
const child = (0, import_node_child_process.spawn)("sudo", [caddyPath]);
|
|
234
|
+
const child = import_node_process2.default.platform === "win32" ? (0, import_node_child_process.spawn)(caddyPath, []) : (0, import_node_child_process.spawn)("sudo", [caddyPath]);
|
|
235
|
+
child.on("close", () => {
|
|
236
|
+
return resolve(true);
|
|
237
|
+
});
|
|
235
238
|
child.on("error", (err) => {
|
|
236
|
-
reject(err);
|
|
239
|
+
return reject(err);
|
|
237
240
|
});
|
|
238
241
|
child.stdout.on("data", (_data) => {
|
|
239
|
-
resolve(true);
|
|
242
|
+
return resolve(true);
|
|
240
243
|
});
|
|
241
244
|
});
|
|
242
245
|
}
|
|
@@ -305,8 +308,9 @@ var CaddyInstant = class {
|
|
|
305
308
|
* @returns
|
|
306
309
|
*/
|
|
307
310
|
async run(source, target, options) {
|
|
311
|
+
source = source.replace("0.0.0.0", "127.0.0.1").replace("localhost", "127.0.0.1");
|
|
308
312
|
const {
|
|
309
|
-
restore =
|
|
313
|
+
restore = true,
|
|
310
314
|
base = "/"
|
|
311
315
|
} = options || {};
|
|
312
316
|
if (!this.inited)
|
|
@@ -315,8 +319,10 @@ var CaddyInstant = class {
|
|
|
315
319
|
throw new Error("update host failed");
|
|
316
320
|
if (await tryPort(443))
|
|
317
321
|
await (0, import_kill_port.default)(443, "tcp");
|
|
322
|
+
if (import_node_process2.default.platform === "win32" && await tryPort(80))
|
|
323
|
+
await (0, import_kill_port.default)(80, "tcp");
|
|
318
324
|
return new Promise((resolve, reject) => {
|
|
319
|
-
const child = (0, import_node_child_process.spawn)("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
325
|
+
const child = import_node_process2.default.platform !== "win32" ? (0, import_node_child_process.spawn)("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]) : (0, import_node_child_process.spawn)(caddyPath, ["reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
320
326
|
child.on("error", (err) => {
|
|
321
327
|
return reject(err);
|
|
322
328
|
});
|
|
@@ -327,6 +333,7 @@ var CaddyInstant = class {
|
|
|
327
333
|
}
|
|
328
334
|
});
|
|
329
335
|
child.stdout.on("data", (_data) => {
|
|
336
|
+
console.log(_data.toString());
|
|
330
337
|
resolve(async () => {
|
|
331
338
|
if (!restore)
|
|
332
339
|
return;
|
|
@@ -344,8 +351,10 @@ var CaddyInstant = class {
|
|
|
344
351
|
|
|
345
352
|
// src/index.ts
|
|
346
353
|
var config;
|
|
354
|
+
var caddy;
|
|
347
355
|
var unpluginFactory = (options) => ({
|
|
348
356
|
name: "unplugin-https-reverse-proxy",
|
|
357
|
+
enforce: "post",
|
|
349
358
|
vite: {
|
|
350
359
|
configResolved(_config) {
|
|
351
360
|
config = _config;
|
|
@@ -368,8 +377,8 @@ var unpluginFactory = (options) => ({
|
|
|
368
377
|
}
|
|
369
378
|
const base = server.config.base || "/";
|
|
370
379
|
try {
|
|
371
|
-
const
|
|
372
|
-
|
|
380
|
+
const caddy2 = new CaddyInstant();
|
|
381
|
+
caddy2.run(source, target, {
|
|
373
382
|
base
|
|
374
383
|
}).then((stop) => {
|
|
375
384
|
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
@@ -387,7 +396,6 @@ var unpluginFactory = (options) => ({
|
|
|
387
396
|
}
|
|
388
397
|
},
|
|
389
398
|
webpack(compiler) {
|
|
390
|
-
var _a, _b;
|
|
391
399
|
const {
|
|
392
400
|
target = ""
|
|
393
401
|
} = options;
|
|
@@ -395,16 +403,25 @@ var unpluginFactory = (options) => ({
|
|
|
395
403
|
console.log("please provide target");
|
|
396
404
|
return;
|
|
397
405
|
}
|
|
398
|
-
const source = `${((_a = compiler.options.devServer) == null ? void 0 : _a.host) || "127.0.0.1"}:${((_b = compiler.options.devServer) == null ? void 0 : _b.port) || "8080"}`;
|
|
399
406
|
try {
|
|
400
|
-
const
|
|
407
|
+
const devServer = compiler.options.devServer || import_node_process3.default.VUE_CLI_SERVICE.projectOptions.devServer;
|
|
408
|
+
const source = `${(devServer == null ? void 0 : devServer.host) || "127.0.0.1"}:${(devServer == null ? void 0 : devServer.port) || "8080"}`;
|
|
409
|
+
if (caddy)
|
|
410
|
+
return;
|
|
411
|
+
caddy = new CaddyInstant();
|
|
401
412
|
caddy.run(source, target).then((stop) => {
|
|
402
413
|
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
403
|
-
|
|
414
|
+
compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
|
|
415
|
+
if (stats.hasErrors())
|
|
416
|
+
return;
|
|
417
|
+
console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
|
|
418
|
+
});
|
|
404
419
|
import_node_process3.default.on("SIGINT", async () => {
|
|
405
420
|
await stop();
|
|
406
421
|
import_node_process3.default.exit();
|
|
407
422
|
});
|
|
423
|
+
}).catch((e) => {
|
|
424
|
+
throw e;
|
|
408
425
|
});
|
|
409
426
|
} catch (e) {
|
|
410
427
|
console.error(e);
|
package/dist/nuxt.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
vite_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-CCEFFLWU.js";
|
|
4
4
|
import {
|
|
5
5
|
webpack_default
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-YJTJH7KX.js";
|
|
7
|
+
import "./chunk-BWNBY4RY.js";
|
|
8
8
|
|
|
9
9
|
// src/nuxt.ts
|
|
10
10
|
import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
|
package/dist/rollup.cjs
CHANGED
|
@@ -55,7 +55,7 @@ var import_kill_port = __toESM(require("kill-port"), 1);
|
|
|
55
55
|
var import_node_path = require("path");
|
|
56
56
|
var import_node_process = __toESM(require("process"), 1);
|
|
57
57
|
var TEMP_DIR = import_node_process.default.env.TEMP || import_node_process.default.env.TMPDIR || "/tmp";
|
|
58
|
-
var caddyPath = (0, import_node_path.join)(TEMP_DIR,
|
|
58
|
+
var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process.default.platform === "win32" ? ".exe" : ""}`);
|
|
59
59
|
var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
|
|
60
60
|
var supportList = [
|
|
61
61
|
{
|
|
@@ -228,12 +228,15 @@ function testCaddy() {
|
|
|
228
228
|
if (!(0, import_node_fs.existsSync)(caddyPath))
|
|
229
229
|
return resolve(false);
|
|
230
230
|
(0, import_node_fs.chmodSync)(caddyPath, 493);
|
|
231
|
-
const child = (0, import_node_child_process.spawn)("sudo", [caddyPath]);
|
|
231
|
+
const child = import_node_process2.default.platform === "win32" ? (0, import_node_child_process.spawn)(caddyPath, []) : (0, import_node_child_process.spawn)("sudo", [caddyPath]);
|
|
232
|
+
child.on("close", () => {
|
|
233
|
+
return resolve(true);
|
|
234
|
+
});
|
|
232
235
|
child.on("error", (err) => {
|
|
233
|
-
reject(err);
|
|
236
|
+
return reject(err);
|
|
234
237
|
});
|
|
235
238
|
child.stdout.on("data", (_data) => {
|
|
236
|
-
resolve(true);
|
|
239
|
+
return resolve(true);
|
|
237
240
|
});
|
|
238
241
|
});
|
|
239
242
|
}
|
|
@@ -302,8 +305,9 @@ var CaddyInstant = class {
|
|
|
302
305
|
* @returns
|
|
303
306
|
*/
|
|
304
307
|
async run(source, target, options) {
|
|
308
|
+
source = source.replace("0.0.0.0", "127.0.0.1").replace("localhost", "127.0.0.1");
|
|
305
309
|
const {
|
|
306
|
-
restore =
|
|
310
|
+
restore = true,
|
|
307
311
|
base = "/"
|
|
308
312
|
} = options || {};
|
|
309
313
|
if (!this.inited)
|
|
@@ -312,8 +316,10 @@ var CaddyInstant = class {
|
|
|
312
316
|
throw new Error("update host failed");
|
|
313
317
|
if (await tryPort(443))
|
|
314
318
|
await (0, import_kill_port.default)(443, "tcp");
|
|
319
|
+
if (import_node_process2.default.platform === "win32" && await tryPort(80))
|
|
320
|
+
await (0, import_kill_port.default)(80, "tcp");
|
|
315
321
|
return new Promise((resolve, reject) => {
|
|
316
|
-
const child = (0, import_node_child_process.spawn)("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
322
|
+
const child = import_node_process2.default.platform !== "win32" ? (0, import_node_child_process.spawn)("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]) : (0, import_node_child_process.spawn)(caddyPath, ["reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
317
323
|
child.on("error", (err) => {
|
|
318
324
|
return reject(err);
|
|
319
325
|
});
|
|
@@ -324,6 +330,7 @@ var CaddyInstant = class {
|
|
|
324
330
|
}
|
|
325
331
|
});
|
|
326
332
|
child.stdout.on("data", (_data) => {
|
|
333
|
+
console.log(_data.toString());
|
|
327
334
|
resolve(async () => {
|
|
328
335
|
if (!restore)
|
|
329
336
|
return;
|
|
@@ -341,8 +348,10 @@ var CaddyInstant = class {
|
|
|
341
348
|
|
|
342
349
|
// src/index.ts
|
|
343
350
|
var config;
|
|
351
|
+
var caddy;
|
|
344
352
|
var unpluginFactory = (options) => ({
|
|
345
353
|
name: "unplugin-https-reverse-proxy",
|
|
354
|
+
enforce: "post",
|
|
346
355
|
vite: {
|
|
347
356
|
configResolved(_config) {
|
|
348
357
|
config = _config;
|
|
@@ -365,8 +374,8 @@ var unpluginFactory = (options) => ({
|
|
|
365
374
|
}
|
|
366
375
|
const base = server.config.base || "/";
|
|
367
376
|
try {
|
|
368
|
-
const
|
|
369
|
-
|
|
377
|
+
const caddy2 = new CaddyInstant();
|
|
378
|
+
caddy2.run(source, target, {
|
|
370
379
|
base
|
|
371
380
|
}).then((stop) => {
|
|
372
381
|
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
@@ -384,7 +393,6 @@ var unpluginFactory = (options) => ({
|
|
|
384
393
|
}
|
|
385
394
|
},
|
|
386
395
|
webpack(compiler) {
|
|
387
|
-
var _a, _b;
|
|
388
396
|
const {
|
|
389
397
|
target = ""
|
|
390
398
|
} = options;
|
|
@@ -392,16 +400,25 @@ var unpluginFactory = (options) => ({
|
|
|
392
400
|
console.log("please provide target");
|
|
393
401
|
return;
|
|
394
402
|
}
|
|
395
|
-
const source = `${((_a = compiler.options.devServer) == null ? void 0 : _a.host) || "127.0.0.1"}:${((_b = compiler.options.devServer) == null ? void 0 : _b.port) || "8080"}`;
|
|
396
403
|
try {
|
|
397
|
-
const
|
|
404
|
+
const devServer = compiler.options.devServer || import_node_process3.default.VUE_CLI_SERVICE.projectOptions.devServer;
|
|
405
|
+
const source = `${(devServer == null ? void 0 : devServer.host) || "127.0.0.1"}:${(devServer == null ? void 0 : devServer.port) || "8080"}`;
|
|
406
|
+
if (caddy)
|
|
407
|
+
return;
|
|
408
|
+
caddy = new CaddyInstant();
|
|
398
409
|
caddy.run(source, target).then((stop) => {
|
|
399
410
|
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
400
|
-
|
|
411
|
+
compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
|
|
412
|
+
if (stats.hasErrors())
|
|
413
|
+
return;
|
|
414
|
+
console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
|
|
415
|
+
});
|
|
401
416
|
import_node_process3.default.on("SIGINT", async () => {
|
|
402
417
|
await stop();
|
|
403
418
|
import_node_process3.default.exit();
|
|
404
419
|
});
|
|
420
|
+
}).catch((e) => {
|
|
421
|
+
throw e;
|
|
405
422
|
});
|
|
406
423
|
} catch (e) {
|
|
407
424
|
console.error(e);
|
package/dist/rollup.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -55,7 +55,7 @@ var import_kill_port = __toESM(require("kill-port"), 1);
|
|
|
55
55
|
var import_node_path = require("path");
|
|
56
56
|
var import_node_process = __toESM(require("process"), 1);
|
|
57
57
|
var TEMP_DIR = import_node_process.default.env.TEMP || import_node_process.default.env.TMPDIR || "/tmp";
|
|
58
|
-
var caddyPath = (0, import_node_path.join)(TEMP_DIR,
|
|
58
|
+
var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process.default.platform === "win32" ? ".exe" : ""}`);
|
|
59
59
|
var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
|
|
60
60
|
var supportList = [
|
|
61
61
|
{
|
|
@@ -228,12 +228,15 @@ function testCaddy() {
|
|
|
228
228
|
if (!(0, import_node_fs.existsSync)(caddyPath))
|
|
229
229
|
return resolve(false);
|
|
230
230
|
(0, import_node_fs.chmodSync)(caddyPath, 493);
|
|
231
|
-
const child = (0, import_node_child_process.spawn)("sudo", [caddyPath]);
|
|
231
|
+
const child = import_node_process2.default.platform === "win32" ? (0, import_node_child_process.spawn)(caddyPath, []) : (0, import_node_child_process.spawn)("sudo", [caddyPath]);
|
|
232
|
+
child.on("close", () => {
|
|
233
|
+
return resolve(true);
|
|
234
|
+
});
|
|
232
235
|
child.on("error", (err) => {
|
|
233
|
-
reject(err);
|
|
236
|
+
return reject(err);
|
|
234
237
|
});
|
|
235
238
|
child.stdout.on("data", (_data) => {
|
|
236
|
-
resolve(true);
|
|
239
|
+
return resolve(true);
|
|
237
240
|
});
|
|
238
241
|
});
|
|
239
242
|
}
|
|
@@ -302,8 +305,9 @@ var CaddyInstant = class {
|
|
|
302
305
|
* @returns
|
|
303
306
|
*/
|
|
304
307
|
async run(source, target, options) {
|
|
308
|
+
source = source.replace("0.0.0.0", "127.0.0.1").replace("localhost", "127.0.0.1");
|
|
305
309
|
const {
|
|
306
|
-
restore =
|
|
310
|
+
restore = true,
|
|
307
311
|
base = "/"
|
|
308
312
|
} = options || {};
|
|
309
313
|
if (!this.inited)
|
|
@@ -312,8 +316,10 @@ var CaddyInstant = class {
|
|
|
312
316
|
throw new Error("update host failed");
|
|
313
317
|
if (await tryPort(443))
|
|
314
318
|
await (0, import_kill_port.default)(443, "tcp");
|
|
319
|
+
if (import_node_process2.default.platform === "win32" && await tryPort(80))
|
|
320
|
+
await (0, import_kill_port.default)(80, "tcp");
|
|
315
321
|
return new Promise((resolve, reject) => {
|
|
316
|
-
const child = (0, import_node_child_process.spawn)("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
322
|
+
const child = import_node_process2.default.platform !== "win32" ? (0, import_node_child_process.spawn)("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]) : (0, import_node_child_process.spawn)(caddyPath, ["reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
317
323
|
child.on("error", (err) => {
|
|
318
324
|
return reject(err);
|
|
319
325
|
});
|
|
@@ -324,6 +330,7 @@ var CaddyInstant = class {
|
|
|
324
330
|
}
|
|
325
331
|
});
|
|
326
332
|
child.stdout.on("data", (_data) => {
|
|
333
|
+
console.log(_data.toString());
|
|
327
334
|
resolve(async () => {
|
|
328
335
|
if (!restore)
|
|
329
336
|
return;
|
|
@@ -341,8 +348,10 @@ var CaddyInstant = class {
|
|
|
341
348
|
|
|
342
349
|
// src/index.ts
|
|
343
350
|
var config;
|
|
351
|
+
var caddy;
|
|
344
352
|
var unpluginFactory = (options) => ({
|
|
345
353
|
name: "unplugin-https-reverse-proxy",
|
|
354
|
+
enforce: "post",
|
|
346
355
|
vite: {
|
|
347
356
|
configResolved(_config) {
|
|
348
357
|
config = _config;
|
|
@@ -365,8 +374,8 @@ var unpluginFactory = (options) => ({
|
|
|
365
374
|
}
|
|
366
375
|
const base = server.config.base || "/";
|
|
367
376
|
try {
|
|
368
|
-
const
|
|
369
|
-
|
|
377
|
+
const caddy2 = new CaddyInstant();
|
|
378
|
+
caddy2.run(source, target, {
|
|
370
379
|
base
|
|
371
380
|
}).then((stop) => {
|
|
372
381
|
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
@@ -384,7 +393,6 @@ var unpluginFactory = (options) => ({
|
|
|
384
393
|
}
|
|
385
394
|
},
|
|
386
395
|
webpack(compiler) {
|
|
387
|
-
var _a, _b;
|
|
388
396
|
const {
|
|
389
397
|
target = ""
|
|
390
398
|
} = options;
|
|
@@ -392,16 +400,25 @@ var unpluginFactory = (options) => ({
|
|
|
392
400
|
console.log("please provide target");
|
|
393
401
|
return;
|
|
394
402
|
}
|
|
395
|
-
const source = `${((_a = compiler.options.devServer) == null ? void 0 : _a.host) || "127.0.0.1"}:${((_b = compiler.options.devServer) == null ? void 0 : _b.port) || "8080"}`;
|
|
396
403
|
try {
|
|
397
|
-
const
|
|
404
|
+
const devServer = compiler.options.devServer || import_node_process3.default.VUE_CLI_SERVICE.projectOptions.devServer;
|
|
405
|
+
const source = `${(devServer == null ? void 0 : devServer.host) || "127.0.0.1"}:${(devServer == null ? void 0 : devServer.port) || "8080"}`;
|
|
406
|
+
if (caddy)
|
|
407
|
+
return;
|
|
408
|
+
caddy = new CaddyInstant();
|
|
398
409
|
caddy.run(source, target).then((stop) => {
|
|
399
410
|
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
400
|
-
|
|
411
|
+
compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
|
|
412
|
+
if (stats.hasErrors())
|
|
413
|
+
return;
|
|
414
|
+
console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
|
|
415
|
+
});
|
|
401
416
|
import_node_process3.default.on("SIGINT", async () => {
|
|
402
417
|
await stop();
|
|
403
418
|
import_node_process3.default.exit();
|
|
404
419
|
});
|
|
420
|
+
}).catch((e) => {
|
|
421
|
+
throw e;
|
|
405
422
|
});
|
|
406
423
|
} catch (e) {
|
|
407
424
|
console.error(e);
|
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -55,7 +55,7 @@ var import_kill_port = __toESM(require("kill-port"), 1);
|
|
|
55
55
|
var import_node_path = require("path");
|
|
56
56
|
var import_node_process = __toESM(require("process"), 1);
|
|
57
57
|
var TEMP_DIR = import_node_process.default.env.TEMP || import_node_process.default.env.TMPDIR || "/tmp";
|
|
58
|
-
var caddyPath = (0, import_node_path.join)(TEMP_DIR,
|
|
58
|
+
var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process.default.platform === "win32" ? ".exe" : ""}`);
|
|
59
59
|
var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
|
|
60
60
|
var supportList = [
|
|
61
61
|
{
|
|
@@ -228,12 +228,15 @@ function testCaddy() {
|
|
|
228
228
|
if (!(0, import_node_fs.existsSync)(caddyPath))
|
|
229
229
|
return resolve(false);
|
|
230
230
|
(0, import_node_fs.chmodSync)(caddyPath, 493);
|
|
231
|
-
const child = (0, import_node_child_process.spawn)("sudo", [caddyPath]);
|
|
231
|
+
const child = import_node_process2.default.platform === "win32" ? (0, import_node_child_process.spawn)(caddyPath, []) : (0, import_node_child_process.spawn)("sudo", [caddyPath]);
|
|
232
|
+
child.on("close", () => {
|
|
233
|
+
return resolve(true);
|
|
234
|
+
});
|
|
232
235
|
child.on("error", (err) => {
|
|
233
|
-
reject(err);
|
|
236
|
+
return reject(err);
|
|
234
237
|
});
|
|
235
238
|
child.stdout.on("data", (_data) => {
|
|
236
|
-
resolve(true);
|
|
239
|
+
return resolve(true);
|
|
237
240
|
});
|
|
238
241
|
});
|
|
239
242
|
}
|
|
@@ -302,8 +305,9 @@ var CaddyInstant = class {
|
|
|
302
305
|
* @returns
|
|
303
306
|
*/
|
|
304
307
|
async run(source, target, options) {
|
|
308
|
+
source = source.replace("0.0.0.0", "127.0.0.1").replace("localhost", "127.0.0.1");
|
|
305
309
|
const {
|
|
306
|
-
restore =
|
|
310
|
+
restore = true,
|
|
307
311
|
base = "/"
|
|
308
312
|
} = options || {};
|
|
309
313
|
if (!this.inited)
|
|
@@ -312,8 +316,10 @@ var CaddyInstant = class {
|
|
|
312
316
|
throw new Error("update host failed");
|
|
313
317
|
if (await tryPort(443))
|
|
314
318
|
await (0, import_kill_port.default)(443, "tcp");
|
|
319
|
+
if (import_node_process2.default.platform === "win32" && await tryPort(80))
|
|
320
|
+
await (0, import_kill_port.default)(80, "tcp");
|
|
315
321
|
return new Promise((resolve, reject) => {
|
|
316
|
-
const child = (0, import_node_child_process.spawn)("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
322
|
+
const child = import_node_process2.default.platform !== "win32" ? (0, import_node_child_process.spawn)("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]) : (0, import_node_child_process.spawn)(caddyPath, ["reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
317
323
|
child.on("error", (err) => {
|
|
318
324
|
return reject(err);
|
|
319
325
|
});
|
|
@@ -324,6 +330,7 @@ var CaddyInstant = class {
|
|
|
324
330
|
}
|
|
325
331
|
});
|
|
326
332
|
child.stdout.on("data", (_data) => {
|
|
333
|
+
console.log(_data.toString());
|
|
327
334
|
resolve(async () => {
|
|
328
335
|
if (!restore)
|
|
329
336
|
return;
|
|
@@ -341,8 +348,10 @@ var CaddyInstant = class {
|
|
|
341
348
|
|
|
342
349
|
// src/index.ts
|
|
343
350
|
var config;
|
|
351
|
+
var caddy;
|
|
344
352
|
var unpluginFactory = (options) => ({
|
|
345
353
|
name: "unplugin-https-reverse-proxy",
|
|
354
|
+
enforce: "post",
|
|
346
355
|
vite: {
|
|
347
356
|
configResolved(_config) {
|
|
348
357
|
config = _config;
|
|
@@ -365,8 +374,8 @@ var unpluginFactory = (options) => ({
|
|
|
365
374
|
}
|
|
366
375
|
const base = server.config.base || "/";
|
|
367
376
|
try {
|
|
368
|
-
const
|
|
369
|
-
|
|
377
|
+
const caddy2 = new CaddyInstant();
|
|
378
|
+
caddy2.run(source, target, {
|
|
370
379
|
base
|
|
371
380
|
}).then((stop) => {
|
|
372
381
|
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
@@ -384,7 +393,6 @@ var unpluginFactory = (options) => ({
|
|
|
384
393
|
}
|
|
385
394
|
},
|
|
386
395
|
webpack(compiler) {
|
|
387
|
-
var _a, _b;
|
|
388
396
|
const {
|
|
389
397
|
target = ""
|
|
390
398
|
} = options;
|
|
@@ -392,16 +400,25 @@ var unpluginFactory = (options) => ({
|
|
|
392
400
|
console.log("please provide target");
|
|
393
401
|
return;
|
|
394
402
|
}
|
|
395
|
-
const source = `${((_a = compiler.options.devServer) == null ? void 0 : _a.host) || "127.0.0.1"}:${((_b = compiler.options.devServer) == null ? void 0 : _b.port) || "8080"}`;
|
|
396
403
|
try {
|
|
397
|
-
const
|
|
404
|
+
const devServer = compiler.options.devServer || import_node_process3.default.VUE_CLI_SERVICE.projectOptions.devServer;
|
|
405
|
+
const source = `${(devServer == null ? void 0 : devServer.host) || "127.0.0.1"}:${(devServer == null ? void 0 : devServer.port) || "8080"}`;
|
|
406
|
+
if (caddy)
|
|
407
|
+
return;
|
|
408
|
+
caddy = new CaddyInstant();
|
|
398
409
|
caddy.run(source, target).then((stop) => {
|
|
399
410
|
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
400
|
-
|
|
411
|
+
compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
|
|
412
|
+
if (stats.hasErrors())
|
|
413
|
+
return;
|
|
414
|
+
console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
|
|
415
|
+
});
|
|
401
416
|
import_node_process3.default.on("SIGINT", async () => {
|
|
402
417
|
await stop();
|
|
403
418
|
import_node_process3.default.exit();
|
|
404
419
|
});
|
|
420
|
+
}).catch((e) => {
|
|
421
|
+
throw e;
|
|
405
422
|
});
|
|
406
423
|
} catch (e) {
|
|
407
424
|
console.error(e);
|
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.4",
|
|
5
5
|
"packageManager": "pnpm@8.6.12",
|
|
6
6
|
"description": "",
|
|
7
7
|
"license": "MIT",
|
|
@@ -101,6 +101,7 @@
|
|
|
101
101
|
}
|
|
102
102
|
},
|
|
103
103
|
"dependencies": {
|
|
104
|
+
"esno": "^0.17.0",
|
|
104
105
|
"got-cjs": "^12.5.4",
|
|
105
106
|
"hostile": "^1.3.3",
|
|
106
107
|
"http-proxy-agent": "^7.0.0",
|
|
@@ -119,7 +120,6 @@
|
|
|
119
120
|
"bumpp": "^9.2.0",
|
|
120
121
|
"chalk": "^5.3.0",
|
|
121
122
|
"eslint": "^8.47.0",
|
|
122
|
-
"esno": "^0.17.0",
|
|
123
123
|
"fast-glob": "^3.3.1",
|
|
124
124
|
"nodemon": "^3.0.1",
|
|
125
125
|
"rimraf": "^5.0.1",
|