vite-plugin-rpx 0.11.2 → 0.11.4

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
@@ -29,7 +29,7 @@ bun add vite-plugin-pretty-urls-https
29
29
 
30
30
  ## Usage
31
31
 
32
- ### In your vite.config.js:
32
+ ### In your vite.config.js
33
33
 
34
34
  ```js
35
35
  import { defineConfig } from 'vite'
@@ -99,6 +99,7 @@ export default defineConfig({
99
99
  ```
100
100
 
101
101
  Key differences:
102
+
102
103
  - No WebSocket port allocation issues
103
104
  - No separate proxy server running
104
105
  - More streamlined approach
@@ -128,7 +129,7 @@ This approach is much simpler and avoids the complex port allocation logic that
128
129
 
129
130
  If your browser doesn't trust the certificates:
130
131
 
131
- 1. Navigate to `https://yourapp.localhost`
132
+ 1. Navigate to `<https://yourapp.localhost>`
132
133
  2. Accept the security warning
133
134
  3. The certificate should be stored in your system keychain
134
135
 
package/dist/index.js CHANGED
@@ -4216,11 +4216,12 @@ var init_dns = __esm(async () => {
4216
4216
  });
4217
4217
 
4218
4218
  // src/index.ts
4219
- import { exec as exec2, spawn as spawn2 } from "node:child_process";
4219
+ import { exec as exec3, spawn as spawn2 } from "node:child_process";
4220
4220
  import * as process19 from "node:process";
4221
4221
  import { promisify as promisify2 } from "node:util";
4222
4222
 
4223
4223
  // ../rpx/src/start.ts
4224
+ import { execSync as execSync3 } from "node:child_process";
4224
4225
  import * as http from "node:http";
4225
4226
  import * as http2 from "node:http2";
4226
4227
  import * as net2 from "node:net";
@@ -4247,7 +4248,7 @@ var colors = {
4247
4248
  cyan: c(36, 39)
4248
4249
  };
4249
4250
  // ../rpx/package.json
4250
- var version = "0.11.2";
4251
+ var version = "0.11.4";
4251
4252
 
4252
4253
  // ../rpx/src/config.ts
4253
4254
  import { homedir as homedir3 } from "node:os";
@@ -15120,6 +15121,17 @@ async function startProxies(options) {
15120
15121
  debugLog("watch", "No start command found in config", verbose);
15121
15122
  }
15122
15123
  const primaryDomain = "proxies" in mergedOptions && Array.isArray(mergedOptions.proxies) ? mergedOptions.proxies[0]?.to : ("to" in mergedOptions) ? mergedOptions.to : "rpx.localhost";
15124
+ if (process18.platform !== "win32" && (mergedOptions.https || mergedOptions.cleanup?.hosts !== false)) {
15125
+ const sudoPassword = getSudoPassword();
15126
+ if (!sudoPassword) {
15127
+ try {
15128
+ debugLog("sudo", "Pre-acquiring sudo credentials for privileged operations", verbose);
15129
+ execSync3("sudo -v", { stdio: "inherit" });
15130
+ } catch {
15131
+ debugLog("sudo", "Could not pre-acquire sudo credentials", verbose);
15132
+ }
15133
+ }
15134
+ }
15123
15135
  if (mergedOptions.https) {
15124
15136
  let existingSSLConfig = await checkExistingCertificates(mergedOptions);
15125
15137
  if (!existingSSLConfig) {
@@ -15223,7 +15235,8 @@ async function startProxies(options) {
15223
15235
  fromPort,
15224
15236
  sourceHost: fromUrl.host,
15225
15237
  cleanUrls: option.cleanUrls || false,
15226
- changeOrigin: option.changeOrigin || false
15238
+ changeOrigin: option.changeOrigin || false,
15239
+ pathRewrites: option.pathRewrites
15227
15240
  });
15228
15241
  debugLog("proxies", `Route: ${domain} → ${fromUrl.host}`, verbose);
15229
15242
  if (!domain.includes("localhost") && !domain.includes("127.0.0.1")) {
@@ -15269,10 +15282,24 @@ async function startProxies(options) {
15269
15282
  debugLog("request", `No route found for host: ${hostname}`, verbose);
15270
15283
  return new Response(`No proxy configured for ${hostname}`, { status: 404 });
15271
15284
  }
15272
- const targetUrl = `http://${route.sourceHost}${url.pathname}${url.search}`;
15285
+ let targetHost = route.sourceHost;
15286
+ let targetPath = url.pathname;
15287
+ if (route.pathRewrites) {
15288
+ for (const rewrite of route.pathRewrites) {
15289
+ if (url.pathname === rewrite.from || url.pathname.startsWith(`${rewrite.from}/`)) {
15290
+ targetHost = rewrite.to.startsWith("http") ? new URL(rewrite.to).host : rewrite.to;
15291
+ if (rewrite.stripPrefix !== false) {
15292
+ targetPath = url.pathname.slice(rewrite.from.length) || "/";
15293
+ }
15294
+ debugLog("request", `Path rewrite: ${url.pathname} → ${targetHost}${targetPath}`, verbose);
15295
+ break;
15296
+ }
15297
+ }
15298
+ }
15299
+ const targetUrl = `http://${targetHost}${targetPath}${url.search}`;
15273
15300
  try {
15274
15301
  const headers = new Headers(req.headers);
15275
- headers.set("host", route.sourceHost);
15302
+ headers.set("host", targetHost);
15276
15303
  if (route.changeOrigin) {
15277
15304
  headers.set("origin", `http://${route.sourceHost}`);
15278
15305
  }
@@ -15393,7 +15420,7 @@ function buildConfig(options, serverUrl) {
15393
15420
  }
15394
15421
 
15395
15422
  // src/index.ts
15396
- var execAsync2 = promisify2(exec2);
15423
+ var execAsync2 = promisify2(exec3);
15397
15424
  async function checkInitialSudo() {
15398
15425
  try {
15399
15426
  await execAsync2("sudo -n true");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-plugin-rpx",
3
3
  "type": "module",
4
- "version": "0.11.2",
4
+ "version": "0.11.4",
5
5
  "description": "A modern and smart reverse proxy. Vite plugin.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -47,7 +47,7 @@
47
47
  "typecheck": "bunx tsc --noEmit"
48
48
  },
49
49
  "dependencies": {
50
- "@stacksjs/rpx": "0.11.2",
50
+ "@stacksjs/rpx": "0.11.4",
51
51
  "@stacksjs/tlsx": "^0.13.0"
52
52
  },
53
53
  "devDependencies": {