unplugin-https-reverse-proxy 1.0.0-beta.0 → 1.0.0-beta.10
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 +94 -1
- package/dist/{chunk-3RTK3FSZ.js → chunk-RUJE3YFB.js} +21 -0
- package/dist/{chunk-KYMRDRAJ.js → chunk-XLSIGDFU.js} +135 -77
- package/dist/esbuild.cjs +153 -79
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +157 -81
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +6 -4
- package/dist/nuxt.cjs +101 -134
- package/dist/nuxt.js +29 -9
- package/dist/rollup.cjs +153 -79
- package/dist/rollup.js +2 -2
- package/dist/rspack.cjs +643 -0
- package/dist/rspack.d.cts +5 -0
- package/dist/rspack.d.ts +5 -0
- package/dist/rspack.js +10 -0
- package/dist/utils.cjs +25 -2
- package/dist/utils.d.cts +3 -1
- package/dist/utils.d.ts +3 -1
- package/dist/utils.js +7 -3
- package/dist/vite.cjs +153 -79
- package/dist/vite.d.cts +1 -2
- package/dist/vite.d.ts +1 -2
- package/dist/vite.js +7 -4
- package/dist/webpack.cjs +153 -79
- package/dist/webpack.js +7 -4
- package/package.json +42 -24
- package/src/caddy/constants.ts +13 -1
- package/src/caddy/index.ts +32 -5
- package/src/host/index.ts +4 -1
- package/src/index.ts +128 -85
- package/src/nuxt.ts +33 -6
- package/src/rspack.ts +5 -0
- package/src/utils.ts +21 -0
- package/dist/chunk-AXBUFN6T.js +0 -11
- package/dist/chunk-MDJOTQRD.js +0 -11
package/dist/rspack.cjs
ADDED
|
@@ -0,0 +1,643 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __export = (target, all) => {
|
|
23
|
+
for (var name in all)
|
|
24
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
25
|
+
};
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(from))
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
|
+
}
|
|
32
|
+
return to;
|
|
33
|
+
};
|
|
34
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
35
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
36
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
37
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
38
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
39
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
40
|
+
mod
|
|
41
|
+
));
|
|
42
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
43
|
+
|
|
44
|
+
// src/rspack.ts
|
|
45
|
+
var rspack_exports = {};
|
|
46
|
+
__export(rspack_exports, {
|
|
47
|
+
default: () => rspack_default
|
|
48
|
+
});
|
|
49
|
+
module.exports = __toCommonJS(rspack_exports);
|
|
50
|
+
|
|
51
|
+
// src/index.ts
|
|
52
|
+
var import_node_process5 = __toESM(require("process"), 1);
|
|
53
|
+
var import_unplugin = require("unplugin");
|
|
54
|
+
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
55
|
+
|
|
56
|
+
// src/utils.ts
|
|
57
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
58
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
59
|
+
var import_promises = require("fs/promises");
|
|
60
|
+
var import_node_child_process = require("child_process");
|
|
61
|
+
var import_consola = require("consola");
|
|
62
|
+
var consola = (0, import_consola.createConsola)({
|
|
63
|
+
level: 3
|
|
64
|
+
}).withTag("reverse-proxy");
|
|
65
|
+
async function chmodRecursive(_path, mode) {
|
|
66
|
+
await (0, import_promises.chmod)(_path, mode);
|
|
67
|
+
if ((await (0, import_promises.stat)(_path)).isDirectory()) {
|
|
68
|
+
const children = await (0, import_promises.readdir)(_path);
|
|
69
|
+
for (const child of children)
|
|
70
|
+
await chmodRecursive(import_node_path.default.join(_path, child), mode);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function once(fn) {
|
|
74
|
+
let called = false;
|
|
75
|
+
return (...args) => {
|
|
76
|
+
if (called)
|
|
77
|
+
return;
|
|
78
|
+
called = true;
|
|
79
|
+
return fn(...args);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function isAdmin() {
|
|
83
|
+
if (import_node_process.default.platform === "win32") {
|
|
84
|
+
try {
|
|
85
|
+
(0, import_node_child_process.execSync)("net session", { stdio: "ignore" });
|
|
86
|
+
return true;
|
|
87
|
+
} catch (e) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
return import_node_process.default.getuid && import_node_process.default.getuid() === 0;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/caddy/index.ts
|
|
96
|
+
var import_node_os2 = require("os");
|
|
97
|
+
var import_node_process4 = __toESM(require("process"), 1);
|
|
98
|
+
var import_node_fs2 = require("fs");
|
|
99
|
+
var import_node_child_process3 = require("child_process");
|
|
100
|
+
var import_got_cjs = require("got-cjs");
|
|
101
|
+
var import_http_proxy_agent = require("http-proxy-agent");
|
|
102
|
+
var import_https_proxy_agent = require("https-proxy-agent");
|
|
103
|
+
var import_kill_port = __toESM(require("kill-port"), 1);
|
|
104
|
+
|
|
105
|
+
// src/host/index.ts
|
|
106
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
107
|
+
var import_node_child_process2 = require("child_process");
|
|
108
|
+
var import_node_fs = require("fs");
|
|
109
|
+
var import_hosts_so_easy = __toESM(require("hosts-so-easy"), 1);
|
|
110
|
+
var Hosts = import_hosts_so_easy.default.default || import_hosts_so_easy.default;
|
|
111
|
+
var hostInstance = new Hosts({
|
|
112
|
+
debounceTime: 50,
|
|
113
|
+
hostsFile: getPathOfSystemHostsPath()
|
|
114
|
+
});
|
|
115
|
+
function getPathOfSystemHostsPath() {
|
|
116
|
+
return import_node_process2.default.platform === "win32" ? `${import_node_process2.default.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
|
|
117
|
+
}
|
|
118
|
+
async function syncHost() {
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
(0, import_node_child_process2.exec)(
|
|
121
|
+
import_node_process2.default.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
|
|
122
|
+
(error, stdout, stderr) => {
|
|
123
|
+
if (error) {
|
|
124
|
+
consola.error(`exec error: ${error}`);
|
|
125
|
+
return resolve(false);
|
|
126
|
+
}
|
|
127
|
+
return resolve(true);
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
async function addHost(ip, host) {
|
|
133
|
+
if (import_node_process2.default.platform !== "win32")
|
|
134
|
+
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
135
|
+
hostInstance.add("127.0.0.1", "localhost");
|
|
136
|
+
hostInstance.add(ip, host);
|
|
137
|
+
if (ip === "localhost")
|
|
138
|
+
hostInstance.add("127.0.0.1", host);
|
|
139
|
+
await hostInstance.updateFinish();
|
|
140
|
+
return await syncHost();
|
|
141
|
+
}
|
|
142
|
+
async function removeHost(ip, host) {
|
|
143
|
+
if (import_node_process2.default.platform !== "win32")
|
|
144
|
+
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
145
|
+
hostInstance.remove(ip, host);
|
|
146
|
+
if (ip === "localhost")
|
|
147
|
+
hostInstance.remove("127.0.0.1", host);
|
|
148
|
+
await hostInstance.updateFinish();
|
|
149
|
+
return await syncHost();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/caddy/constants.ts
|
|
153
|
+
var import_node_path2 = require("path");
|
|
154
|
+
var import_node_os = __toESM(require("os"), 1);
|
|
155
|
+
var import_node_process3 = __toESM(require("process"), 1);
|
|
156
|
+
var import_dotenv_flow = __toESM(require("dotenv-flow"), 1);
|
|
157
|
+
import_dotenv_flow.default.config({
|
|
158
|
+
silent: true
|
|
159
|
+
});
|
|
160
|
+
function resolvePath(path2) {
|
|
161
|
+
if (path2.startsWith("~"))
|
|
162
|
+
return (0, import_node_path2.join)(import_node_os.default.homedir() || "", path2.slice(1));
|
|
163
|
+
return path2;
|
|
164
|
+
}
|
|
165
|
+
var TEMP_DIR = resolvePath(import_node_process3.default.env.UHRP_CADDY_PATH || import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp");
|
|
166
|
+
var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
|
|
167
|
+
var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
|
|
168
|
+
var supportList = [
|
|
169
|
+
{
|
|
170
|
+
platform: "dragonfly",
|
|
171
|
+
arch: "amd64"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
platform: "freebsd",
|
|
175
|
+
arch: "amd64"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
platform: "freebsd",
|
|
179
|
+
arch: "arm-6"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
platform: "freebsd",
|
|
183
|
+
arch: "arm-7"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
platform: "freebsd",
|
|
187
|
+
arch: "arm64"
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
platform: "linux",
|
|
191
|
+
arch: "amd64"
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
platform: "linux",
|
|
195
|
+
arch: "arm-5"
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
platform: "linux",
|
|
199
|
+
arch: "arm-6"
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
platform: "linux",
|
|
203
|
+
arch: "arm-7"
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
platform: "linux",
|
|
207
|
+
arch: "arm64"
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
platform: "linux",
|
|
211
|
+
arch: "mips"
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
platform: "linux",
|
|
215
|
+
arch: "mips64"
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
platform: "linux",
|
|
219
|
+
arch: "mips64le"
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
platform: "linux",
|
|
223
|
+
arch: "mipsle"
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
platform: "linux",
|
|
227
|
+
arch: "ppc64"
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
platform: "linux",
|
|
231
|
+
arch: "ppc64le"
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
platform: "linux",
|
|
235
|
+
arch: "s390x"
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
platform: "darwin",
|
|
239
|
+
arch: "amd64"
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
platform: "darwin",
|
|
243
|
+
arch: "arm64"
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
platform: "openbsd",
|
|
247
|
+
arch: "amd64"
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
platform: "openbsd",
|
|
251
|
+
arch: "arm-6"
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
platform: "openbsd",
|
|
255
|
+
arch: "arm-7"
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
platform: "openbsd",
|
|
259
|
+
arch: "arm64"
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
platform: "windows",
|
|
263
|
+
arch: "amd64"
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
platform: "windows",
|
|
267
|
+
arch: "arm-6"
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
platform: "windows",
|
|
271
|
+
arch: "arm-7"
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
platform: "windows",
|
|
275
|
+
arch: "arm64"
|
|
276
|
+
}
|
|
277
|
+
];
|
|
278
|
+
|
|
279
|
+
// src/caddy/utils.ts
|
|
280
|
+
var import_node_net = require("net");
|
|
281
|
+
var import_ora = __toESM(require("ora"), 1);
|
|
282
|
+
var spinner;
|
|
283
|
+
function tryPort(port) {
|
|
284
|
+
return new Promise((resolve, reject) => {
|
|
285
|
+
try {
|
|
286
|
+
const server = (0, import_node_net.createServer)().listen(port);
|
|
287
|
+
server.on("listening", () => {
|
|
288
|
+
server.close();
|
|
289
|
+
resolve(false);
|
|
290
|
+
});
|
|
291
|
+
server.on("error", (err) => {
|
|
292
|
+
if (err.code === "EADDRINUSE")
|
|
293
|
+
resolve(true);
|
|
294
|
+
server.close();
|
|
295
|
+
});
|
|
296
|
+
} catch (e) {
|
|
297
|
+
resolve(true);
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
function getNumber(number) {
|
|
302
|
+
if (number <= 0)
|
|
303
|
+
return "0%";
|
|
304
|
+
else if (number < 100)
|
|
305
|
+
return `${number.toFixed(2)}%`;
|
|
306
|
+
else
|
|
307
|
+
return "100%";
|
|
308
|
+
}
|
|
309
|
+
function logProgress(percent) {
|
|
310
|
+
if (!spinner) {
|
|
311
|
+
consola.log("");
|
|
312
|
+
spinner = (0, import_ora.default)({
|
|
313
|
+
text: "Start Download Caddy: 0%",
|
|
314
|
+
indent: 2
|
|
315
|
+
});
|
|
316
|
+
spinner.start();
|
|
317
|
+
} else {
|
|
318
|
+
spinner.text = `Download Caddy: ${getNumber(Number(percent) * 100)}`;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
function logProgressOver() {
|
|
322
|
+
if (!spinner) {
|
|
323
|
+
spinner = (0, import_ora.default)({
|
|
324
|
+
text: "Start Download Caddy: 100%",
|
|
325
|
+
indent: 2
|
|
326
|
+
});
|
|
327
|
+
spinner.start();
|
|
328
|
+
} else {
|
|
329
|
+
spinner.succeed();
|
|
330
|
+
consola.log("");
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// src/caddy/index.ts
|
|
335
|
+
async function download() {
|
|
336
|
+
if (await testCaddy())
|
|
337
|
+
return caddyPath;
|
|
338
|
+
return new Promise((resolve, reject) => {
|
|
339
|
+
if (!(0, import_node_fs2.existsSync)(TEMP_DIR)) {
|
|
340
|
+
(0, import_node_fs2.mkdirSync)(TEMP_DIR, { recursive: true });
|
|
341
|
+
(0, import_node_fs2.chmodSync)(TEMP_DIR, 511);
|
|
342
|
+
}
|
|
343
|
+
const file = (0, import_node_fs2.createWriteStream)(caddyPath);
|
|
344
|
+
let _platform = (0, import_node_os2.platform)().toString();
|
|
345
|
+
_platform === "win32" && (_platform = "windows");
|
|
346
|
+
let _arch = import_node_process4.default.arch.toString();
|
|
347
|
+
_arch === "x64" && (_arch = "amd64");
|
|
348
|
+
const support = supportList.find((item) => item.platform === _platform && item.arch === _arch);
|
|
349
|
+
if (!support)
|
|
350
|
+
return reject(new Error("not support"));
|
|
351
|
+
const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}`;
|
|
352
|
+
(0, import_node_fs2.existsSync)(caddyPath) && (0, import_node_fs2.unlinkSync)(caddyPath);
|
|
353
|
+
const httpProxy = import_node_process4.default.env.HTTP_PROXY || import_node_process4.default.env.http_proxy;
|
|
354
|
+
const httpsProxy = import_node_process4.default.env.HTTPS_PROXY || import_node_process4.default.env.https_proxy;
|
|
355
|
+
const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
|
|
356
|
+
const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
|
|
357
|
+
const chmodCaddyOnce = once(() => {
|
|
358
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
359
|
+
});
|
|
360
|
+
import_got_cjs.got.stream(dowmloadLink, {
|
|
361
|
+
agent: {
|
|
362
|
+
http: httpAgent,
|
|
363
|
+
https: httpsAgent
|
|
364
|
+
}
|
|
365
|
+
}).on("downloadProgress", (progress) => {
|
|
366
|
+
logProgress(progress.percent);
|
|
367
|
+
chmodCaddyOnce();
|
|
368
|
+
}).pipe(file).on("finish", () => {
|
|
369
|
+
logProgressOver();
|
|
370
|
+
if (import_node_process4.default.platform === "win32")
|
|
371
|
+
return resolve(caddyPath);
|
|
372
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
373
|
+
resolve(caddyPath);
|
|
374
|
+
}).on("error", (err) => {
|
|
375
|
+
reject(err);
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
function testCaddy() {
|
|
380
|
+
return new Promise((resolve, reject) => {
|
|
381
|
+
if (!(0, import_node_fs2.existsSync)(caddyPath))
|
|
382
|
+
return resolve(false);
|
|
383
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
384
|
+
const child = import_node_process4.default.platform === "win32" ? (0, import_node_child_process3.spawn)(caddyPath, []) : (0, import_node_child_process3.spawn)("sudo", ["-E", caddyPath]);
|
|
385
|
+
child.on("close", () => {
|
|
386
|
+
return resolve(false);
|
|
387
|
+
});
|
|
388
|
+
child.on("error", (err) => {
|
|
389
|
+
return reject(err);
|
|
390
|
+
});
|
|
391
|
+
child.stdout.on("data", (_data) => {
|
|
392
|
+
return resolve(true);
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
var CaddyInstant = class {
|
|
397
|
+
constructor() {
|
|
398
|
+
this.inited = false;
|
|
399
|
+
this.stoped = false;
|
|
400
|
+
testCaddy().then(() => {
|
|
401
|
+
this.inited = true;
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
async init() {
|
|
405
|
+
await download();
|
|
406
|
+
this.inited = true;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* @param source like `127.0.0.1:8080`
|
|
410
|
+
* @param target like `test.abc.com`. And if you provide a port ,it will be ignore.
|
|
411
|
+
* @returns
|
|
412
|
+
*/
|
|
413
|
+
async run(source, target, options) {
|
|
414
|
+
source = source.replace("0.0.0.0", "127.0.0.1");
|
|
415
|
+
const {
|
|
416
|
+
restore = true,
|
|
417
|
+
base = "/",
|
|
418
|
+
showCaddyLog = false,
|
|
419
|
+
https = false
|
|
420
|
+
} = options || {};
|
|
421
|
+
if (!this.inited)
|
|
422
|
+
await this.init();
|
|
423
|
+
if (https && await tryPort(443))
|
|
424
|
+
await (0, import_kill_port.default)(443, "tcp");
|
|
425
|
+
if ((import_node_process4.default.platform === "win32" || !https) && await tryPort(80))
|
|
426
|
+
await (0, import_kill_port.default)(80, "tcp");
|
|
427
|
+
if (!await addHost(source.split(":")[0], target.split(":")[0]))
|
|
428
|
+
throw new Error("update host failed");
|
|
429
|
+
consola.success("update host success\n");
|
|
430
|
+
return new Promise((resolve, reject) => {
|
|
431
|
+
const child = import_node_process4.default.platform !== "win32" ? (0, import_node_child_process3.spawn)("sudo", ["-E", caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}${https ? "" : ":80"}`, "--to", `${source}`, "--internal-certs", "--insecure", "--disable-redirects"]) : (0, import_node_child_process3.spawn)(caddyPath, ["reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
432
|
+
child.on("error", (err) => {
|
|
433
|
+
return reject(err);
|
|
434
|
+
});
|
|
435
|
+
import_node_process4.default.on("SIGINT", async () => {
|
|
436
|
+
if (!restore || this.stoped)
|
|
437
|
+
return;
|
|
438
|
+
try {
|
|
439
|
+
if (await removeHost(source.split(":")[0], target.split(":")[0]))
|
|
440
|
+
consola.success("restore host success\n");
|
|
441
|
+
else
|
|
442
|
+
consola.fail("restore host failed\n");
|
|
443
|
+
} catch (e) {
|
|
444
|
+
consola.error(e);
|
|
445
|
+
consola.fail("restore host failed\n");
|
|
446
|
+
} finally {
|
|
447
|
+
this.stoped = true;
|
|
448
|
+
import_node_process4.default.nextTick(() => {
|
|
449
|
+
import_node_process4.default.exit();
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
const originalExit = import_node_process4.default.exit.bind(import_node_process4.default);
|
|
454
|
+
import_node_process4.default.exit = async (code) => {
|
|
455
|
+
const port = Number(source.split(":")[1]);
|
|
456
|
+
if (!Number.isNaN(port) && await tryPort(port))
|
|
457
|
+
await (0, import_kill_port.default)(port, "tcp");
|
|
458
|
+
const pwd = import_node_process4.default.cwd();
|
|
459
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
460
|
+
if ((0, import_node_fs2.existsSync)(viteCacheDir))
|
|
461
|
+
chmodRecursive(viteCacheDir, 511);
|
|
462
|
+
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
463
|
+
if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
|
|
464
|
+
await chmodRecursive(nuxtCacheDir, 511);
|
|
465
|
+
const webpackCacheDir = `${pwd}/node_modules/.cache`;
|
|
466
|
+
if ((0, import_node_fs2.existsSync)(webpackCacheDir))
|
|
467
|
+
chmodRecursive(webpackCacheDir, 511);
|
|
468
|
+
if (!restore || this.stoped)
|
|
469
|
+
return originalExit(code);
|
|
470
|
+
try {
|
|
471
|
+
if (await removeHost(source.split(":")[0], target.split(":")[0]))
|
|
472
|
+
consola.success("restore host success\n");
|
|
473
|
+
else
|
|
474
|
+
consola.fail("restore host failed\n");
|
|
475
|
+
} catch (e) {
|
|
476
|
+
consola.error(e);
|
|
477
|
+
consola.fail("restore host failed\n");
|
|
478
|
+
} finally {
|
|
479
|
+
this.stoped = true;
|
|
480
|
+
import_node_process4.default.nextTick(() => {
|
|
481
|
+
originalExit(code);
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
child.stderr.on("data", (data) => {
|
|
486
|
+
const lines = data.toString().split("\n").map((line) => line.trim());
|
|
487
|
+
for (const line of lines) {
|
|
488
|
+
showCaddyLog && line && console.info(line);
|
|
489
|
+
if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
|
|
490
|
+
consola.error(line);
|
|
491
|
+
return reject(line);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
child.stdout.on("data", (_data) => {
|
|
496
|
+
consola.info(_data.toString());
|
|
497
|
+
resolve();
|
|
498
|
+
});
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
// src/index.ts
|
|
504
|
+
var config;
|
|
505
|
+
var caddy;
|
|
506
|
+
var cwd = import_node_process5.default.cwd();
|
|
507
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
508
|
+
_printUrls == null ? void 0 : _printUrls();
|
|
509
|
+
if (caddy)
|
|
510
|
+
return;
|
|
511
|
+
caddy = new CaddyInstant();
|
|
512
|
+
caddy.run(source, target, __spreadValues({
|
|
513
|
+
base
|
|
514
|
+
}, options)).then(() => {
|
|
515
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
516
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
517
|
+
}).catch((e) => {
|
|
518
|
+
throw e;
|
|
519
|
+
});
|
|
520
|
+
});
|
|
521
|
+
var unpluginFactory = (options) => ({
|
|
522
|
+
name: "unplugin-https-reverse-proxy",
|
|
523
|
+
enforce: "pre",
|
|
524
|
+
vite: {
|
|
525
|
+
configResolved(_config) {
|
|
526
|
+
config = _config;
|
|
527
|
+
},
|
|
528
|
+
configureServer(server) {
|
|
529
|
+
var _a;
|
|
530
|
+
if (config.command !== "serve")
|
|
531
|
+
return;
|
|
532
|
+
const {
|
|
533
|
+
enable = true,
|
|
534
|
+
target = ""
|
|
535
|
+
} = options;
|
|
536
|
+
if (!enable)
|
|
537
|
+
return;
|
|
538
|
+
if (!isAdmin()) {
|
|
539
|
+
consola.warn("please run as administrator");
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
if (!target) {
|
|
543
|
+
consola.fail("please provide target");
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
const _printUrls = server.printUrls.bind(server);
|
|
547
|
+
let source = `localhost:${config.server.port || 5173}`;
|
|
548
|
+
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
549
|
+
if (url) {
|
|
550
|
+
const u = new URL(url);
|
|
551
|
+
source = u.host;
|
|
552
|
+
}
|
|
553
|
+
const base = server.config.base || "/";
|
|
554
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
|
|
555
|
+
}
|
|
556
|
+
},
|
|
557
|
+
webpack(compiler) {
|
|
558
|
+
var _a, _b;
|
|
559
|
+
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
560
|
+
return;
|
|
561
|
+
const {
|
|
562
|
+
enable = true,
|
|
563
|
+
target = ""
|
|
564
|
+
} = options;
|
|
565
|
+
if (!enable)
|
|
566
|
+
return;
|
|
567
|
+
if (!isAdmin()) {
|
|
568
|
+
consola.warn("please run as administrator");
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
if (!target) {
|
|
572
|
+
consola.fail("please provide target");
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
const devServer = __spreadValues(__spreadValues({
|
|
576
|
+
host: "localhost",
|
|
577
|
+
port: 8080
|
|
578
|
+
}, compiler.options.devServer), (_a = import_node_process5.default.VUE_CLI_SERVICE) == null ? void 0 : _a.projectOptions.devServer);
|
|
579
|
+
const source = `${devServer.host}:${devServer.port}`;
|
|
580
|
+
if (caddy)
|
|
581
|
+
return;
|
|
582
|
+
const _close = (_b = compiler.close) == null ? void 0 : _b.bind(compiler);
|
|
583
|
+
if (_close) {
|
|
584
|
+
compiler.close = async (callback) => {
|
|
585
|
+
import_node_process5.default.on("exit", () => {
|
|
586
|
+
_close && _close(callback);
|
|
587
|
+
});
|
|
588
|
+
};
|
|
589
|
+
} else {
|
|
590
|
+
options.https = false;
|
|
591
|
+
}
|
|
592
|
+
caddy = new CaddyInstant();
|
|
593
|
+
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
594
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
595
|
+
compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
|
|
596
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
597
|
+
});
|
|
598
|
+
}).catch((e) => {
|
|
599
|
+
throw e;
|
|
600
|
+
});
|
|
601
|
+
},
|
|
602
|
+
async rspack(compiler) {
|
|
603
|
+
var _a, _b, _c;
|
|
604
|
+
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
605
|
+
return;
|
|
606
|
+
const {
|
|
607
|
+
enable = true,
|
|
608
|
+
target = ""
|
|
609
|
+
} = options;
|
|
610
|
+
if (!enable)
|
|
611
|
+
return;
|
|
612
|
+
if (!isAdmin()) {
|
|
613
|
+
consola.warn("please run as administrator");
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
if (!target) {
|
|
617
|
+
consola.fail("please provide target");
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
const devServer = __spreadValues(__spreadValues({
|
|
621
|
+
host: "localhost",
|
|
622
|
+
port: 8080
|
|
623
|
+
}, compiler.options.devServer), (_c = (_b = await ((_a = await import("@rsbuild/core")) == null ? void 0 : _a.loadConfig({
|
|
624
|
+
cwd
|
|
625
|
+
}))) == null ? void 0 : _b.content) == null ? void 0 : _c.server);
|
|
626
|
+
const source = `${devServer.host}:${devServer.port}`;
|
|
627
|
+
if (caddy)
|
|
628
|
+
return;
|
|
629
|
+
caddy = new CaddyInstant();
|
|
630
|
+
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
631
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
632
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
633
|
+
}).catch((e) => {
|
|
634
|
+
throw e;
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
var unplugin = /* @__PURE__ */ (0, import_unplugin.createUnplugin)(unpluginFactory);
|
|
639
|
+
var src_default = unplugin;
|
|
640
|
+
|
|
641
|
+
// src/rspack.ts
|
|
642
|
+
var rspack_default = src_default.rspack;
|
|
643
|
+
exports.default = module.exports;
|
package/dist/rspack.d.ts
ADDED