unplugin-https-reverse-proxy 1.0.0-beta.2 → 1.0.0-beta.21

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 CHANGED
@@ -2,10 +2,19 @@
2
2
 
3
3
  [![NPM version](https://img.shields.io/npm/v/unplugin-https-reverse-proxy?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-https-reverse-proxy)
4
4
 
5
- A plugin for https reverse proxy, support `vite` and `webpack`.
5
+ A plugin for https reverse proxy, support `vite`、`webpack` and `rspack`.
6
6
 
7
7
  ## Install
8
8
 
9
+
10
+ Support set caddy file path by environment variable `UHRP_CADDY_PATH`, default is system cache folder.
11
+
12
+ ```env
13
+ #.env.local
14
+ UHRP_CADDY_PATH=~/tmp/.uhrp
15
+ ```
16
+
17
+
9
18
  ```bash
10
19
  # not auto install caddy when postinstall
11
20
  npm i unplugin-https-reverse-proxy --save-dev
@@ -115,6 +124,90 @@ module.exports = {
115
124
 
116
125
  <br></details>
117
126
 
127
+ <details>
128
+ <summary>Rspack</summary><br>
129
+
130
+ ```js
131
+ // rspack.config.js
132
+
133
+ /** @type {Parameters<import('unplugin-https-reverse-proxy/webpack')['default']>[0]} */
134
+ const reverseProxyOptions = {
135
+ enable: false,
136
+ target: 'xxx',
137
+ https: false,
138
+ }
139
+
140
+ module.exports = {
141
+ /* ... */
142
+ devServer: {
143
+ client: {
144
+ // ↓ for HMR
145
+ webSocketURL: {
146
+ ...(reverseProxyOptions.enable
147
+ ? {
148
+ hostname: reverseProxyOptions.target,
149
+ }
150
+ : {}),
151
+ ...(reverseProxyOptions.enable && reverseProxyOptions.https
152
+ ? {
153
+ protocol: 'wss',
154
+ port: 443,
155
+ }
156
+ : {})
157
+ }
158
+ },
159
+ },
160
+ plugins: [
161
+ require('unplugin-https-reverse-proxy/rspack')(reverseProxyOptions)
162
+ ]
163
+ }
164
+ ```
165
+
166
+ <br></details>
167
+
168
+ <details>
169
+ <summary>Rsbuild</summary><br>
170
+
171
+ ```js
172
+ // rsbuild.config.js
173
+
174
+ /** @type {Parameters<import('unplugin-https-reverse-proxy/webpack')['default']>[0]} */
175
+ const reverseProxyOptions = {
176
+ enable: false,
177
+ target: 'xxx',
178
+ https: false,
179
+ }
180
+
181
+ module.exports = {
182
+ /* ... */
183
+ dev: {
184
+ client: {
185
+ // ↓ for HMR
186
+ ...(reverseProxyOptions.enable
187
+ ? {
188
+ host: reverseProxyOptions.target,
189
+ }
190
+ : {}),
191
+ ...(reverseProxyOptions.enable && reverseProxyOptions.https
192
+ ? {
193
+ protocol: 'wss',
194
+ port: '443',
195
+ }
196
+ : {})
197
+ },
198
+ },
199
+ tools: {
200
+ rspack: {
201
+ plugins: [
202
+ require('unplugin-https-reverse-proxy/rspack')(reverseProxyOptions)
203
+ ]
204
+ },
205
+ },
206
+ }
207
+ ```
208
+
209
+ <br></details>
210
+
118
211
  <details>
119
212
  <summary>Nuxt</summary><br>
120
213
 
@@ -127,7 +220,17 @@ export default defineNuxtConfig({
127
220
  })
128
221
  ```
129
222
 
130
- > This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite)
223
+ **!important:** You need to update the `nuxt dev` script by adding `--fork=false` to enable host restoration.
224
+
225
+ ```json
226
+ // package.json
227
+
228
+ {
229
+ "scripts": {
230
+ "dev": "nuxt dev --fork=false"
231
+ }
232
+ }
233
+ ```
131
234
 
132
235
  <br></details>
133
236
 
@@ -0,0 +1,45 @@
1
+ // src/utils.ts
2
+ import process from "node:process";
3
+ import path from "node:path";
4
+ import { chmod, readdir, stat } from "node:fs/promises";
5
+ import { execSync } from "node:child_process";
6
+ import { createConsola } from "consola";
7
+ var consola = createConsola({
8
+ level: 3
9
+ }).withTag("reverse-proxy");
10
+ async function chmodRecursive(_path, mode) {
11
+ await chmod(_path, mode);
12
+ if ((await stat(_path)).isDirectory()) {
13
+ const children = await readdir(_path);
14
+ for (const child of children)
15
+ await chmodRecursive(path.join(_path, child), mode);
16
+ }
17
+ }
18
+ function once(fn) {
19
+ let called = false;
20
+ return (...args) => {
21
+ if (called)
22
+ return;
23
+ called = true;
24
+ return fn(...args);
25
+ };
26
+ }
27
+ function isAdmin() {
28
+ if (process.platform === "win32") {
29
+ try {
30
+ execSync("net session", { stdio: "ignore" });
31
+ return true;
32
+ } catch {
33
+ return false;
34
+ }
35
+ } else {
36
+ return process.getuid && process.getuid() === 0;
37
+ }
38
+ }
39
+
40
+ export {
41
+ consola,
42
+ chmodRecursive,
43
+ once,
44
+ isAdmin
45
+ };