unplugin-https-reverse-proxy 1.0.0-beta.2 → 1.0.0-beta.20
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 +105 -2
- package/dist/chunk-2VGRJ3QS.js +45 -0
- package/dist/chunk-I6DP2OII.js +695 -0
- package/dist/esbuild.cjs +334 -160
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +334 -160
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +2 -2
- package/dist/nuxt.cjs +270 -234
- package/dist/nuxt.js +24 -22
- package/dist/rollup.cjs +334 -160
- package/dist/rollup.js +2 -2
- package/dist/rspack.cjs +760 -0
- package/dist/rspack.d.cts +5 -0
- package/dist/rspack.d.ts +5 -0
- package/dist/rspack.js +10 -0
- package/dist/types.cjs +1 -1
- package/dist/utils.cjs +2 -2
- package/dist/utils.js +1 -1
- package/dist/vite.cjs +334 -160
- package/dist/vite.d.cts +1 -2
- package/dist/vite.d.ts +1 -2
- package/dist/vite.js +7 -4
- package/dist/webpack.cjs +334 -160
- package/dist/webpack.js +7 -4
- package/package.json +48 -28
- package/scripts/postinstall.cjs +308 -0
- package/src/caddy/constants.ts +14 -1
- package/src/caddy/index.ts +230 -76
- package/src/caddy/utils.ts +18 -0
- package/src/host/index.ts +9 -15
- package/src/index.ts +110 -83
- package/src/nuxt.ts +26 -19
- package/src/rspack.ts +5 -0
- package/dist/chunk-DDD5N75Y.js +0 -11
- package/dist/chunk-N6ZBBGYD.js +0 -516
- package/dist/chunk-RUJE3YFB.js +0 -63
- package/dist/chunk-VGLXVBHU.js +0 -11
- package/scripts/postinstall.ts +0 -19
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
|
-
import type { ResolvedConfig
|
|
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
|
|
|
@@ -12,44 +11,30 @@ let config: ResolvedConfig
|
|
|
12
11
|
|
|
13
12
|
let caddy: CaddyInstant
|
|
14
13
|
|
|
15
|
-
const
|
|
14
|
+
const cwd = process.cwd()
|
|
16
15
|
|
|
17
|
-
export
|
|
18
|
-
server: ViteDevServer,
|
|
16
|
+
export const vitePrintUrls = once((
|
|
19
17
|
options: Options,
|
|
20
18
|
source: string,
|
|
21
19
|
target: string,
|
|
22
20
|
base: string = '/',
|
|
23
21
|
_printUrls?: () => void,
|
|
24
|
-
) {
|
|
22
|
+
) => {
|
|
25
23
|
_printUrls?.()
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
base,
|
|
41
|
-
...options,
|
|
42
|
-
}).then(() => {
|
|
43
|
-
const colorUrl = (url: string) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`))
|
|
44
|
-
consola.success(` ${c.green('➜')} ${c.bold('run caddy reverse proxy success')}: ${colorUrl(`${options.https ? 'https' : 'http'}://${target}${base}`)}`)
|
|
45
|
-
}).catch((e) => {
|
|
46
|
-
throw e
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
catch (e) {
|
|
50
|
-
consola.error(e)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
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
|
+
})
|
|
37
|
+
})
|
|
53
38
|
|
|
54
39
|
export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
55
40
|
name: 'unplugin-https-reverse-proxy',
|
|
@@ -59,20 +44,21 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
59
44
|
config = _config
|
|
60
45
|
},
|
|
61
46
|
configureServer(server) {
|
|
62
|
-
if (
|
|
63
|
-
consola.warn('please run as administrator')
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (config.command === 'build')
|
|
47
|
+
if (config.command !== 'serve')
|
|
68
48
|
return
|
|
69
49
|
|
|
70
50
|
const {
|
|
71
51
|
enable = true,
|
|
72
52
|
target = '',
|
|
73
53
|
} = options
|
|
54
|
+
|
|
74
55
|
if (!enable)
|
|
75
56
|
return
|
|
57
|
+
|
|
58
|
+
if (!isAdmin()) {
|
|
59
|
+
consola.warn('please run as administrator')
|
|
60
|
+
return
|
|
61
|
+
}
|
|
76
62
|
if (!target) {
|
|
77
63
|
consola.fail('please provide target')
|
|
78
64
|
return
|
|
@@ -89,15 +75,72 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
89
75
|
|
|
90
76
|
const base = server.config.base || '/'
|
|
91
77
|
|
|
92
|
-
server.printUrls = () => vitePrintUrls(
|
|
78
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls)
|
|
93
79
|
},
|
|
94
80
|
},
|
|
95
81
|
webpack(compiler) {
|
|
82
|
+
if (process.env.NODE_ENV !== 'development')
|
|
83
|
+
return
|
|
84
|
+
|
|
85
|
+
const {
|
|
86
|
+
enable = true,
|
|
87
|
+
target = '',
|
|
88
|
+
} = options
|
|
89
|
+
|
|
90
|
+
if (!enable)
|
|
91
|
+
return
|
|
92
|
+
|
|
96
93
|
if (!isAdmin()) {
|
|
97
94
|
consola.warn('please run as administrator')
|
|
98
95
|
return
|
|
99
96
|
}
|
|
100
97
|
|
|
98
|
+
if (!target) {
|
|
99
|
+
consola.fail('please provide target')
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const devServer = {
|
|
104
|
+
host: 'localhost',
|
|
105
|
+
port: 8080,
|
|
106
|
+
...compiler.options.devServer,
|
|
107
|
+
// @ts-expect-error vuecli
|
|
108
|
+
...(process.VUE_CLI_SERVICE?.projectOptions.devServer),
|
|
109
|
+
}
|
|
110
|
+
const source = `${devServer.host}:${devServer.port}`
|
|
111
|
+
|
|
112
|
+
if (caddy)
|
|
113
|
+
return
|
|
114
|
+
|
|
115
|
+
// https://github.com/webpack/webpack-dev-server/blob/master/lib/Server.js#L1913
|
|
116
|
+
const _close = compiler.close?.bind(compiler)
|
|
117
|
+
if (_close) {
|
|
118
|
+
compiler.close = async (callback: Parameters<typeof _close>[0]) => {
|
|
119
|
+
process.on('exit', () => {
|
|
120
|
+
_close && _close(callback)
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
// webpack 4 not support yet
|
|
126
|
+
options.https = false
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
caddy = new CaddyInstant()
|
|
130
|
+
|
|
131
|
+
caddy.run(source, target, {
|
|
132
|
+
...options,
|
|
133
|
+
}).then(() => {
|
|
134
|
+
const colorUrl = (url: string) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`))
|
|
135
|
+
|
|
136
|
+
compiler.hooks.done.tap('unplugin-https-reverse-proxy', () => {
|
|
137
|
+
consola.success(` ${c.green('➜')} ${c.bold('run caddy reverse proxy success')}: ${colorUrl(`${options.https ? 'https' : 'http'}://${target}`)}`)
|
|
138
|
+
})
|
|
139
|
+
}).catch((e) => {
|
|
140
|
+
throw e
|
|
141
|
+
})
|
|
142
|
+
},
|
|
143
|
+
async rspack(compiler) {
|
|
101
144
|
if (process.env.NODE_ENV !== 'development')
|
|
102
145
|
return
|
|
103
146
|
|
|
@@ -105,61 +148,45 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
105
148
|
enable = true,
|
|
106
149
|
target = '',
|
|
107
150
|
} = options
|
|
151
|
+
|
|
108
152
|
if (!enable)
|
|
109
153
|
return
|
|
154
|
+
|
|
155
|
+
if (!isAdmin()) {
|
|
156
|
+
consola.warn('please run as administrator')
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
|
|
110
160
|
if (!target) {
|
|
111
161
|
consola.fail('please provide target')
|
|
112
162
|
return
|
|
113
163
|
}
|
|
114
164
|
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
...compiler.options.devServer,
|
|
124
|
-
// @ts-expect-error vuecli
|
|
125
|
-
...process.VUE_CLI_SERVICE.projectOptions.devServer,
|
|
126
|
-
}
|
|
127
|
-
const source = `${devServer.host}:${devServer.port}`
|
|
165
|
+
const devServer = {
|
|
166
|
+
host: 'localhost',
|
|
167
|
+
port: 8080,
|
|
168
|
+
...compiler.options.devServer,
|
|
169
|
+
...(await (await import('@rsbuild/core'))?.loadConfig({
|
|
170
|
+
cwd,
|
|
171
|
+
}))?.content?.server,
|
|
172
|
+
}
|
|
128
173
|
|
|
129
|
-
|
|
130
|
-
return
|
|
174
|
+
const source = `${devServer.host}:${devServer.port}`
|
|
131
175
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (_close) {
|
|
135
|
-
compiler.close = async (callback: Parameters<typeof _close>[0]) => {
|
|
136
|
-
process.on('exit', () => {
|
|
137
|
-
_close && _close(callback)
|
|
138
|
-
})
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
// webpack 4 not support yet
|
|
143
|
-
options.https = false
|
|
144
|
-
}
|
|
176
|
+
if (caddy)
|
|
177
|
+
return
|
|
145
178
|
|
|
146
|
-
|
|
179
|
+
caddy = new CaddyInstant()
|
|
147
180
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
181
|
+
caddy.run(source, target, {
|
|
182
|
+
...options,
|
|
183
|
+
}).then(() => {
|
|
184
|
+
const colorUrl = (url: string) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`))
|
|
152
185
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
throw e
|
|
158
|
-
})
|
|
159
|
-
}
|
|
160
|
-
catch (e) {
|
|
161
|
-
consola.error(e)
|
|
162
|
-
}
|
|
186
|
+
consola.success(` ${c.green('➜')} ${c.bold('run caddy reverse proxy success')}: ${colorUrl(`${options.https ? 'https' : 'http'}://${target}`)}`)
|
|
187
|
+
}).catch((e) => {
|
|
188
|
+
throw e
|
|
189
|
+
})
|
|
163
190
|
},
|
|
164
191
|
})
|
|
165
192
|
|
package/src/nuxt.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import vite from './vite'
|
|
4
|
-
import webpack from './webpack'
|
|
1
|
+
import process from 'node:process'
|
|
2
|
+
import { defineNuxtModule } from '@nuxt/kit'
|
|
5
3
|
import type { Options } from './types'
|
|
6
4
|
import '@nuxt/schema'
|
|
7
|
-
import { consola,
|
|
5
|
+
import { consola, isAdmin } from './utils'
|
|
8
6
|
import { vitePrintUrls } from '.'
|
|
9
7
|
|
|
10
8
|
export interface ModuleOptions extends Options {
|
|
@@ -17,26 +15,35 @@ export default defineNuxtModule<ModuleOptions>({
|
|
|
17
15
|
configKey: 'unpluginHttpsReverseProxy',
|
|
18
16
|
},
|
|
19
17
|
setup(options, _nuxt) {
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
if (process.env.NODE_ENV !== 'development')
|
|
19
|
+
return
|
|
20
|
+
|
|
21
|
+
const {
|
|
22
|
+
enable = true,
|
|
23
|
+
target = '',
|
|
24
|
+
} = options
|
|
25
|
+
|
|
26
|
+
if (!enable)
|
|
27
|
+
return
|
|
28
|
+
|
|
29
|
+
if (!isAdmin()) {
|
|
30
|
+
consola.warn('please run as administrator')
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!target) {
|
|
35
|
+
consola.fail('please provide target')
|
|
36
|
+
return
|
|
37
|
+
}
|
|
22
38
|
|
|
23
39
|
// https://github.com/nuxt/cli/issues/220#issuecomment-1735394141
|
|
24
|
-
let url = ''
|
|
25
40
|
_nuxt.hook('listen', (_, listener) => {
|
|
26
|
-
url = listener.url
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
_nuxt.hook('vite:serverCreated', once((server: ViteDevServer) => {
|
|
41
|
+
const url = listener.url
|
|
30
42
|
const source = new URL(url).host
|
|
31
43
|
|
|
32
|
-
if (!options.target) {
|
|
33
|
-
consola.fail('please provide target')
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
|
|
37
44
|
const base = _nuxt.options.app.baseURL || '/'
|
|
38
45
|
|
|
39
|
-
vitePrintUrls(
|
|
40
|
-
})
|
|
46
|
+
vitePrintUrls(options, source, options.target, base)
|
|
47
|
+
})
|
|
41
48
|
},
|
|
42
49
|
})
|
package/src/rspack.ts
ADDED