unplugin-https-reverse-proxy 1.0.0-beta.4 → 1.0.0-beta.7
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 +9 -0
- package/dist/{chunk-GAKOA5LE.js → chunk-IUFVJYJ5.js} +69 -61
- package/dist/esbuild.cjs +70 -62
- package/dist/esbuild.js +1 -1
- package/dist/index.cjs +70 -62
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +44 -29
- package/dist/nuxt.js +3 -3
- package/dist/rollup.cjs +70 -62
- package/dist/rollup.js +1 -1
- package/dist/vite.cjs +70 -62
- package/dist/vite.js +1 -1
- package/dist/webpack.cjs +70 -62
- package/dist/webpack.js +1 -1
- package/package.json +2 -1
- package/src/caddy/constants.ts +11 -1
- package/src/caddy/index.ts +28 -5
- package/src/index.ts +51 -74
- package/src/nuxt.ts +3 -3
package/src/index.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import process from 'node:process'
|
|
2
|
-
import { existsSync } from 'node:fs'
|
|
3
2
|
import type { UnpluginFactory } from 'unplugin'
|
|
4
3
|
import { createUnplugin } from 'unplugin'
|
|
5
4
|
import type { ResolvedConfig } from 'vite'
|
|
6
5
|
import c from 'picocolors'
|
|
7
|
-
import {
|
|
6
|
+
import { consola, isAdmin, once } from './utils'
|
|
8
7
|
import type { Options } from './types'
|
|
9
8
|
import { CaddyInstant } from './caddy'
|
|
10
9
|
|
|
@@ -23,31 +22,18 @@ export const vitePrintUrls = once((
|
|
|
23
22
|
) => {
|
|
24
23
|
_printUrls?.()
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
caddy.run(source, target, {
|
|
39
|
-
base,
|
|
40
|
-
...options,
|
|
41
|
-
}).then(() => {
|
|
42
|
-
const colorUrl = (url: string) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`))
|
|
43
|
-
consola.success(` ${c.green('➜')} ${c.bold('run caddy reverse proxy success')}: ${colorUrl(`${options.https ? 'https' : 'http'}://${target}${base}`)}`)
|
|
44
|
-
}).catch((e) => {
|
|
45
|
-
throw e
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
catch (e) {
|
|
49
|
-
consola.error(e)
|
|
50
|
-
}
|
|
25
|
+
if (caddy)
|
|
26
|
+
return
|
|
27
|
+
caddy = new CaddyInstant()
|
|
28
|
+
caddy.run(source, target, {
|
|
29
|
+
base,
|
|
30
|
+
...options,
|
|
31
|
+
}).then(() => {
|
|
32
|
+
const colorUrl = (url: string) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`))
|
|
33
|
+
consola.success(` ${c.green('➜')} ${c.bold('run caddy reverse proxy success')}: ${colorUrl(`${options.https ? 'https' : 'http'}://${target}${base}`)}`)
|
|
34
|
+
}).catch((e) => {
|
|
35
|
+
throw e
|
|
36
|
+
})
|
|
51
37
|
})
|
|
52
38
|
|
|
53
39
|
export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
@@ -58,14 +44,14 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
58
44
|
config = _config
|
|
59
45
|
},
|
|
60
46
|
configureServer(server) {
|
|
47
|
+
if (config.command !== 'serve')
|
|
48
|
+
return
|
|
49
|
+
|
|
61
50
|
if (!isAdmin()) {
|
|
62
51
|
consola.warn('please run as administrator')
|
|
63
52
|
return
|
|
64
53
|
}
|
|
65
54
|
|
|
66
|
-
if (config.command === 'build')
|
|
67
|
-
return
|
|
68
|
-
|
|
69
55
|
const {
|
|
70
56
|
enable = true,
|
|
71
57
|
target = '',
|
|
@@ -92,14 +78,14 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
92
78
|
},
|
|
93
79
|
},
|
|
94
80
|
webpack(compiler) {
|
|
81
|
+
if (process.env.NODE_ENV !== 'development')
|
|
82
|
+
return
|
|
83
|
+
|
|
95
84
|
if (!isAdmin()) {
|
|
96
85
|
consola.warn('please run as administrator')
|
|
97
86
|
return
|
|
98
87
|
}
|
|
99
88
|
|
|
100
|
-
if (process.env.NODE_ENV !== 'development')
|
|
101
|
-
return
|
|
102
|
-
|
|
103
89
|
const {
|
|
104
90
|
enable = true,
|
|
105
91
|
target = '',
|
|
@@ -111,54 +97,45 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
111
97
|
return
|
|
112
98
|
}
|
|
113
99
|
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
...compiler.options.devServer,
|
|
123
|
-
// @ts-expect-error vuecli
|
|
124
|
-
...process.VUE_CLI_SERVICE.projectOptions.devServer,
|
|
125
|
-
}
|
|
126
|
-
const source = `${devServer.host}:${devServer.port}`
|
|
100
|
+
const devServer = {
|
|
101
|
+
host: 'localhost',
|
|
102
|
+
port: 8080,
|
|
103
|
+
...compiler.options.devServer,
|
|
104
|
+
// @ts-expect-error vuecli
|
|
105
|
+
...process.VUE_CLI_SERVICE.projectOptions.devServer,
|
|
106
|
+
}
|
|
107
|
+
const source = `${devServer.host}:${devServer.port}`
|
|
127
108
|
|
|
128
|
-
|
|
129
|
-
|
|
109
|
+
if (caddy)
|
|
110
|
+
return
|
|
130
111
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
// webpack 4 not support yet
|
|
142
|
-
options.https = false
|
|
112
|
+
// https://github.com/webpack/webpack-dev-server/blob/master/lib/Server.js#L1913
|
|
113
|
+
const _close = compiler.close?.bind(compiler)
|
|
114
|
+
if (_close) {
|
|
115
|
+
compiler.close = async (callback: Parameters<typeof _close>[0]) => {
|
|
116
|
+
process.on('exit', () => {
|
|
117
|
+
_close && _close(callback)
|
|
118
|
+
})
|
|
143
119
|
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
// webpack 4 not support yet
|
|
123
|
+
options.https = false
|
|
124
|
+
}
|
|
144
125
|
|
|
145
|
-
|
|
126
|
+
caddy = new CaddyInstant()
|
|
146
127
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
128
|
+
caddy.run(source, target, {
|
|
129
|
+
...options,
|
|
130
|
+
}).then(() => {
|
|
131
|
+
const colorUrl = (url: string) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`))
|
|
151
132
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
})
|
|
155
|
-
}).catch((e) => {
|
|
156
|
-
throw e
|
|
133
|
+
compiler.hooks.done.tap('unplugin-https-reverse-proxy', () => {
|
|
134
|
+
consola.success(` ${c.green('➜')} ${c.bold('run caddy reverse proxy success')}: ${colorUrl(`${options.https ? 'https' : 'http'}://${target}`)}`)
|
|
157
135
|
})
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
136
|
+
}).catch((e) => {
|
|
137
|
+
throw e
|
|
138
|
+
})
|
|
162
139
|
},
|
|
163
140
|
})
|
|
164
141
|
|
package/src/nuxt.ts
CHANGED
|
@@ -15,14 +15,14 @@ export default defineNuxtModule<ModuleOptions>({
|
|
|
15
15
|
configKey: 'unpluginHttpsReverseProxy',
|
|
16
16
|
},
|
|
17
17
|
setup(options, _nuxt) {
|
|
18
|
+
if (process.env.NODE_ENV !== 'development')
|
|
19
|
+
return
|
|
20
|
+
|
|
18
21
|
if (!isAdmin()) {
|
|
19
22
|
consola.warn('please run as administrator')
|
|
20
23
|
return
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
if (process.env.NODE_ENV !== 'development')
|
|
24
|
-
return
|
|
25
|
-
|
|
26
26
|
const {
|
|
27
27
|
enable = true,
|
|
28
28
|
target = '',
|