Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@stacksjs/rpx

stacksjs1.6kMIT0.9.1TypeScript support: included

A modern and smart reverse proxy.

reverse proxy, ssl, development, environment, proxy, bun, stacks, typescript, javascript

readme

Social Card of this repo

npm version GitHub Actions Commitizen friendly

rpx

A zero-config reverse proxy for local development with SSL support, custom domains, and more—for a better local developer experience.

Features

  • 🔀 Simple, lightweight Reverse Proxy
  • ♾️ Custom Domains (with wildcard support)
  • 0️⃣ Zero-Config Setup
  • 🔒 SSL Support (HTTPS by default)
  • 🛣️ Auto HTTP-to-HTTPS Redirection
  • ✏️ /etc/hosts Management
  • 🧼 Clean URLs (removes .html extension)
  • 🤖 CLI & Library Support

Install

bun install -d @stacksjs/rpx

Get Started

There are two ways of using this reverse proxy: as a library or as a CLI.

Library

Given the npm package is installed:

import type { TlsConfig } from '@stacksjs/rpx'
import { startProxy } from '@stacksjs/rpx'

export interface CleanupConfig {
  hosts: boolean // clean up /etc/hosts, defaults to false
  certs: boolean // clean up certificates, defaults to false
}

export interface ProxyConfig {
  from: string // domain to proxy from, defaults to localhost:5173
  to: string // domain to proxy to, defaults to rpx.localhost
  cleanUrls?: boolean // removes the .html extension from URLs, defaults to false
  https: boolean | TlsConfig // automatically uses https, defaults to true, also redirects http to https
  cleanup?: boolean | CleanupConfig // automatically cleans up /etc/hosts, defaults to false
  start?: StartOptions
  verbose: boolean // log verbose output, defaults to false
}

const config: ProxyOptions = {
  from: 'localhost:5173',
  to: 'rpx.localhost',
  cleanUrls: true,
  https: true,
  cleanup: false,
  start: {
    command: 'bun run dev:docs',
    lazy: true,
  }
}

startProxy(config)

In case you are trying to start multiple proxies, you may use this configuration:

// rpx.config.{ts,js}
import type { ProxyOptions } from '@stacksjs/rpx'
import os from 'node:os'
import path from 'node:path'

const config: ProxyOptions = {
  https: { // https: true -> also works with sensible defaults
    caCertPath: path.join(os.homedir(), '.stacks', 'ssl', `rpx.localhost.ca.crt`),
    certPath: path.join(os.homedir(), '.stacks', 'ssl', `rpx.localhost.crt`),
    keyPath: path.join(os.homedir(), '.stacks', 'ssl', `rpx.localhost.crt.key`),
  },

  cleanup: {
    hosts: true,
    certs: false,
  },

  proxies: [
    {
      from: 'localhost:5173',
      to: 'my-app.localhost',
      cleanUrls: true,
      start: {
        command: 'bun run dev',
        cwd: '/path/to/my-app',
        env: {
          NODE_ENV: 'development',
        },
      },
    },
    {
      from: 'localhost:5174',
      to: 'my-api.local',
    },
  ],

  verbose: true,
}

export default config

CLI

rpx --from localhost:3000 --to my-project.localhost
rpx --from localhost:8080 --to my-project.test --keyPath ./key.pem --certPath ./cert.pem
rpx --help
rpx --version

Configuration

The Reverse Proxy can be configured using a rpx.config.ts (or rpx.config.js) file and it will be automatically loaded when running the reverse-proxy command.

// rpx.config.{ts,js}
import type { ProxyOptions } from '@stacksjs/rpx'
import os from 'node:os'
import path from 'node:path'

const config: ProxyOptions = {
  from: 'localhost:5173',
  to: 'rpx.localhost',

  https: {
    domain: 'rpx.localhost',
    hostCertCN: 'rpx.localhost',
    caCertPath: path.join(os.homedir(), '.stacks', 'ssl', `rpx.localhost.ca.crt`),
    certPath: path.join(os.homedir(), '.stacks', 'ssl', `rpx.localhost.crt`),
    keyPath: path.join(os.homedir(), '.stacks', 'ssl', `rpx.localhost.crt.key`),
    altNameIPs: ['127.0.0.1'],
    altNameURIs: ['localhost'],
    organizationName: 'stacksjs.org',
    countryName: 'US',
    stateName: 'California',
    localityName: 'Playa Vista',
    commonName: 'rpx.localhost',
    validityDays: 180,
    verbose: false,
  },

  verbose: false,
}

export default config

Then run:

./rpx start

To learn more, head over to the documentation.

Testing

bun test

Troubleshooting

SSL Certificate Issues

If you're experiencing SSL certificate issues when using RPX (like "Your connection is not private" browser warnings):

  1. Automatic Certificate Trust: RPX automatically attempts to trust certificates during setup with a single password prompt. This works for most users.

  2. Use the certificate fix utility: If you still see certificate warnings, run our automated certificate fixer:

    bun scripts/fix-certs.js

    This script will:

    • Detect your operating system
    • Find all RPX certificates
    • Install them to the appropriate system trust stores
    • Provide browser-specific instructions
  3. Browser Workaround:

    • Chrome/Edge/Arc: Type thisisunsafe on the warning page (you won't see what you're typing)
    • Firefox: Click "Advanced" then "Accept the Risk and Continue"
    • Safari: Click "Show Details", then "visit this website"

Note: After trusting certificates, restart your browser for changes to take effect.

Changelog

Please see our releases page for more information on what has changed recently.

Contributing

Please review the Contributing Guide for details.

Community

For help, discussion about best practices, or any other conversation that would benefit from being searchable:

Discussions on GitHub

For casual chit-chat with others using this package:

Join the Stacks Discord Server

Postcardware

"Software that is free, but hopes for a postcard." We love receiving postcards from around the world showing where rpx is being used! We showcase them on our website too.

Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States 🌎

Sponsors

We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.

Credits

License

The MIT License (MIT). Please see LICENSE for more information.

Made with 💙

changelog

Changelog

v0.9.1...main

compare changes

🚀 Enhancements

  • Add start option (6ce8217)
  • ci: Add publish-commit workflow (ac87fba)

📖 Documentation

🏡 Chore

❤️ Contributors

v0.9.0...main

compare changes

🏡 Chore

❤️ Contributors

v0.8.1...main

compare changes

🩹 Fixes

  • Properly utilize cleanup (2128973)

🏡 Chore

❤️ Contributors

v0.8.0...main

compare changes

🏡 Chore

❤️ Contributors

v0.7.1...main

compare changes

🚀 Enhancements

  • Allow for cleaning up certificates (a22b7d7)

🏡 Chore

❤️ Contributors

v0.7.0...main

compare changes

🩹 Fixes

  • Properly pass vitePluginUsage (f5b520b)

❤️ Contributors

v0.6.5...main

compare changes

🚀 Enhancements

  • Allow for vite plugin usage (64d7852)

🏡 Chore

❤️ Contributors

v0.6.4...main

compare changes

🏡 Chore

❤️ Contributors

v0.6.3...main

compare changes

🏡 Chore

❤️ Contributors

v0.6.2...main

compare changes

🩹 Fixes

❤️ Contributors

v0.6.1...main

compare changes

🏡 Chore

❤️ Contributors

v0.6.0...main

compare changes

🏡 Chore

❤️ Contributors

v0.5.1...main

compare changes

🚀 Enhancements

🏡 Chore

❤️ Contributors

v0.5.0...main

compare changes

🏡 Chore

  • Move some functionality to utils (5d1effc)
  • Adjust sudo handling (dd194be)

❤️ Contributors

v0.4.1...main

compare changes

🏡 Chore

❤️ Contributors

v0.4.0...main

compare changes

🏡 Chore

  • Update readme (08e61e8)
  • Ensure verbose is configurable (0c2bb22)
  • Add default export (c064d8d)
  • Ensure verbose is false by default (ee341b2)

❤️ Contributors

v0.3.1...main

compare changes

🚀 Enhancements

  • Ensure multiple proxies work (7420091)

🩹 Fixes

  • Ensure /etc/hosts is cleaned if configured (501027c)

🏡 Chore

❤️ Contributors

v0.3.0...main

compare changes

🏡 Chore

❤️ Contributors

v0.2.0...main

compare changes

🚀 Enhancements

🏡 Chore

❤️ Contributors

v0.1.1...main

compare changes

🚀 Enhancements

  • Allow for https boolean (6153960)

🏡 Chore

❤️ Contributors

v0.1.0...main

compare changes

🚀 Enhancements

🏡 Chore

❤️ Contributors

v0.0.1...main

compare changes

🏡 Chore

❤️ Contributors

...main

🏡 Chore

❤️ Contributors