unplugin-https-reverse-proxy 1.0.0-beta.9 → 1.0.0
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 +11 -1
- package/dist/chunk-2VGRJ3QS.js +45 -0
- package/dist/{chunk-ZSHTX2B6.js → chunk-KVE7AVSI.js} +259 -124
- package/dist/esbuild.cjs +250 -128
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +250 -128
- package/dist/index.js +2 -2
- package/dist/nuxt.cjs +223 -110
- package/dist/nuxt.js +7 -7
- package/dist/rollup.cjs +250 -128
- package/dist/rollup.js +2 -2
- package/dist/rspack.cjs +250 -128
- package/dist/rspack.js +2 -2
- package/dist/types.cjs +1 -1
- package/dist/utils.cjs +2 -2
- package/dist/utils.js +1 -1
- package/dist/vite.cjs +250 -128
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +250 -128
- package/dist/webpack.js +2 -2
- package/package.json +11 -8
- package/scripts/postinstall.cjs +308 -0
- package/src/caddy/constants.ts +1 -0
- package/src/caddy/index.ts +225 -94
- package/src/caddy/utils.ts +18 -0
- package/src/host/index.ts +9 -15
- package/src/index.ts +20 -15
- package/src/nuxt.ts +7 -5
- package/dist/chunk-RUJE3YFB.js +0 -63
- package/scripts/postinstall.ts +0 -19
package/src/caddy/utils.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createServer } from 'node:net'
|
|
2
|
+
import { exec } from 'node:child_process'
|
|
2
3
|
import ora from 'ora'
|
|
3
4
|
import { consola } from '../utils'
|
|
4
5
|
|
|
@@ -28,6 +29,23 @@ export function tryPort(port: number) {
|
|
|
28
29
|
})
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
/**
|
|
33
|
+
* npx free-port :port
|
|
34
|
+
*/
|
|
35
|
+
export async function kill(port: number) {
|
|
36
|
+
return new Promise<void>((resolve, reject) => {
|
|
37
|
+
exec(`npx @maxbo/free-port ${port} -s`, (err, stdout, stderr) => {
|
|
38
|
+
if (err) {
|
|
39
|
+
reject(err)
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
consola.log(stdout)
|
|
43
|
+
resolve()
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
31
49
|
function getNumber(number: number) {
|
|
32
50
|
if (number <= 0)
|
|
33
51
|
return '0%'
|
package/src/host/index.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import process from 'node:process'
|
|
2
2
|
import { exec } from 'node:child_process'
|
|
3
3
|
import { chmodSync } from 'node:fs'
|
|
4
|
+
import { promisify } from 'node:util'
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
import _Hosts from 'hosts-so-easy'
|
|
6
|
+
import hostile from 'hostile'
|
|
7
7
|
import { consola } from '../utils'
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const hostInstance = new Hosts({
|
|
12
|
-
debounceTime: 50,
|
|
13
|
-
hostsFile: getPathOfSystemHostsPath(),
|
|
14
|
-
})
|
|
9
|
+
const _setHost = promisify(hostile.set)
|
|
10
|
+
const _removeHost = promisify(hostile.remove)
|
|
15
11
|
|
|
16
12
|
function getPathOfSystemHostsPath() {
|
|
17
13
|
return process.platform === 'win32'
|
|
@@ -38,20 +34,18 @@ async function syncHost() {
|
|
|
38
34
|
export async function addHost(ip: string, host: string) {
|
|
39
35
|
if (process.platform !== 'win32')
|
|
40
36
|
chmodSync(getPathOfSystemHostsPath(), 0o777)
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
await _setHost('127.0.0.1', 'localhost')
|
|
38
|
+
await _setHost(ip, host)
|
|
43
39
|
if (ip === 'localhost')
|
|
44
|
-
|
|
45
|
-
await hostInstance.updateFinish()
|
|
40
|
+
await _setHost('127.0.0.1', host)
|
|
46
41
|
return await syncHost()
|
|
47
42
|
}
|
|
48
43
|
|
|
49
44
|
export async function removeHost(ip: string, host: string) {
|
|
50
45
|
if (process.platform !== 'win32')
|
|
51
46
|
chmodSync(getPathOfSystemHostsPath(), 0o777)
|
|
52
|
-
|
|
47
|
+
await _removeHost(ip, host)
|
|
53
48
|
if (ip === 'localhost')
|
|
54
|
-
|
|
55
|
-
await hostInstance.updateFinish()
|
|
49
|
+
await _removeHost('127.0.0.1', host)
|
|
56
50
|
return await syncHost()
|
|
57
51
|
}
|
package/src/index.ts
CHANGED
|
@@ -47,17 +47,18 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
47
47
|
if (config.command !== 'serve')
|
|
48
48
|
return
|
|
49
49
|
|
|
50
|
-
if (!isAdmin()) {
|
|
51
|
-
consola.warn('please run as administrator')
|
|
52
|
-
return
|
|
53
|
-
}
|
|
54
|
-
|
|
55
50
|
const {
|
|
56
51
|
enable = true,
|
|
57
52
|
target = '',
|
|
58
53
|
} = options
|
|
54
|
+
|
|
59
55
|
if (!enable)
|
|
60
56
|
return
|
|
57
|
+
|
|
58
|
+
if (!isAdmin()) {
|
|
59
|
+
consola.warn('please run as administrator')
|
|
60
|
+
return
|
|
61
|
+
}
|
|
61
62
|
if (!target) {
|
|
62
63
|
consola.fail('please provide target')
|
|
63
64
|
return
|
|
@@ -81,17 +82,19 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
81
82
|
if (process.env.NODE_ENV !== 'development')
|
|
82
83
|
return
|
|
83
84
|
|
|
84
|
-
if (!isAdmin()) {
|
|
85
|
-
consola.warn('please run as administrator')
|
|
86
|
-
return
|
|
87
|
-
}
|
|
88
|
-
|
|
89
85
|
const {
|
|
90
86
|
enable = true,
|
|
91
87
|
target = '',
|
|
92
88
|
} = options
|
|
89
|
+
|
|
93
90
|
if (!enable)
|
|
94
91
|
return
|
|
92
|
+
|
|
93
|
+
if (!isAdmin()) {
|
|
94
|
+
consola.warn('please run as administrator')
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
|
|
95
98
|
if (!target) {
|
|
96
99
|
consola.fail('please provide target')
|
|
97
100
|
return
|
|
@@ -141,17 +144,19 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
141
144
|
if (process.env.NODE_ENV !== 'development')
|
|
142
145
|
return
|
|
143
146
|
|
|
144
|
-
if (!isAdmin()) {
|
|
145
|
-
consola.warn('please run as administrator')
|
|
146
|
-
return
|
|
147
|
-
}
|
|
148
|
-
|
|
149
147
|
const {
|
|
150
148
|
enable = true,
|
|
151
149
|
target = '',
|
|
152
150
|
} = options
|
|
151
|
+
|
|
153
152
|
if (!enable)
|
|
154
153
|
return
|
|
154
|
+
|
|
155
|
+
if (!isAdmin()) {
|
|
156
|
+
consola.warn('please run as administrator')
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
|
|
155
160
|
if (!target) {
|
|
156
161
|
consola.fail('please provide target')
|
|
157
162
|
return
|
package/src/nuxt.ts
CHANGED
|
@@ -18,17 +18,19 @@ export default defineNuxtModule<ModuleOptions>({
|
|
|
18
18
|
if (process.env.NODE_ENV !== 'development')
|
|
19
19
|
return
|
|
20
20
|
|
|
21
|
-
if (!isAdmin()) {
|
|
22
|
-
consola.warn('please run as administrator')
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
|
|
26
21
|
const {
|
|
27
22
|
enable = true,
|
|
28
23
|
target = '',
|
|
29
24
|
} = options
|
|
25
|
+
|
|
30
26
|
if (!enable)
|
|
31
27
|
return
|
|
28
|
+
|
|
29
|
+
if (!isAdmin()) {
|
|
30
|
+
consola.warn('please run as administrator')
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
|
|
32
34
|
if (!target) {
|
|
33
35
|
consola.fail('please provide target')
|
|
34
36
|
return
|
package/dist/chunk-RUJE3YFB.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// src/utils.ts
|
|
19
|
-
import process from "process";
|
|
20
|
-
import path from "path";
|
|
21
|
-
import { chmod, readdir, stat } from "fs/promises";
|
|
22
|
-
import { execSync } from "child_process";
|
|
23
|
-
import { createConsola } from "consola";
|
|
24
|
-
var consola = createConsola({
|
|
25
|
-
level: 3
|
|
26
|
-
}).withTag("reverse-proxy");
|
|
27
|
-
async function chmodRecursive(_path, mode) {
|
|
28
|
-
await chmod(_path, mode);
|
|
29
|
-
if ((await stat(_path)).isDirectory()) {
|
|
30
|
-
const children = await readdir(_path);
|
|
31
|
-
for (const child of children)
|
|
32
|
-
await chmodRecursive(path.join(_path, child), mode);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function once(fn) {
|
|
36
|
-
let called = false;
|
|
37
|
-
return (...args) => {
|
|
38
|
-
if (called)
|
|
39
|
-
return;
|
|
40
|
-
called = true;
|
|
41
|
-
return fn(...args);
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
function isAdmin() {
|
|
45
|
-
if (process.platform === "win32") {
|
|
46
|
-
try {
|
|
47
|
-
execSync("net session", { stdio: "ignore" });
|
|
48
|
-
return true;
|
|
49
|
-
} catch (e) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
return process.getuid && process.getuid() === 0;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export {
|
|
58
|
-
__spreadValues,
|
|
59
|
-
consola,
|
|
60
|
-
chmodRecursive,
|
|
61
|
-
once,
|
|
62
|
-
isAdmin
|
|
63
|
-
};
|
package/scripts/postinstall.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { existsSync, unlinkSync } from 'node:fs'
|
|
2
|
-
import process from 'node:process'
|
|
3
|
-
import { consola } from '../src/utils'
|
|
4
|
-
import { download } from '../src/caddy'
|
|
5
|
-
import { caddyPath } from '../src/caddy/constants'
|
|
6
|
-
|
|
7
|
-
async function run() {
|
|
8
|
-
try {
|
|
9
|
-
if (process.env.UHRP_AUTO_INSTALL_CADDY) {
|
|
10
|
-
existsSync(caddyPath) && unlinkSync(caddyPath)
|
|
11
|
-
await download()
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
catch (e: any) {
|
|
15
|
-
consola.error(e.code)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
run()
|