Skip to content

Single port - multiple proxiesΒ #54

@upeguiborja

Description

@upeguiborja

Clear and concise description of the problem

As a developer I want to access different proxied paths and/or subdomains without having to add different ports for each.

Right now @stacksjs/rpx creates different listeners on different ports

import startProxies, { MultiProxyConfig } from "@stacksjs/rpx";

const config: MultiProxyConfig = {
  https: true,
  cleanup: {
    hosts: true,
    certs: true,
  },
  cleanUrls: false,
  vitePluginUsage: false,

  proxies: [
    {
      from: "localhost:3000",
      to: "foo.myservice.local",
      cleanUrls: true,
    },
    {
      from: "localhost:3001",
      to: "myservice.local/bar",
      cleanUrls: false,
    },
    {
      from: "localhost:3003",
      to: "*.myservice.local",
      cleanUrls: true,
    },
  ],

  verbose: false,
};

startProxies(config);

Output:

  rpx v0.10.0

  ➜  localhost:3000 ➜ https://foo.myservice.local
  ➜  SSL enabled with:
     - TLS 1.2/1.3
     - Modern cipher suite
     - HTTP/2 enabled
     - HSTS enabled

 WARN  Port 80 is in use, HTTP to HTTPS redirect will not be available                                                                                                                   10:25:39 PM


 WARN  Port 443 is in use. Using port 8443 instead.                                                                                                                                      10:25:39 PM

β„Ή You can use 'sudo lsof -i :443' (Unix) or 'netstat -ano | findstr :443' (Windows) to check what's using the port.                                                                     10:25:39 PM

  rpx v0.10.0

  ➜  localhost:3001 ➜ https://myservice.local
  ➜  Listening on port 8443
  ➜  SSL enabled with:
     - TLS 1.2/1.3
     - Modern cipher suite
     - HTTP/2 enabled
     - HSTS enabled

 WARN  Port 80 is in use, HTTP to HTTPS redirect will not be available                                                                                                                   10:25:39 PM


 WARN  Port 443 is in use. Using port 8444 instead.                                                                                                                                      10:25:39 PM

β„Ή You can use 'sudo lsof -i :443' (Unix) or 'netstat -ano | findstr :443' (Windows) to check what's using the port.                                                                     10:25:39 PM

  rpx v0.10.0

  ➜  localhost:3003 ➜ *.myservice.local"
  ➜  Listening on port 8444
  ➜  SSL enabled with:
     - TLS 1.2/1.3
     - Modern cipher suite
     - HTTP/2 enabled
     - HSTS enabled

It created 3 different servers listening on ports 80, 443, 8443 and 8444.

Suggested solution

Add a singlePortMode parameter that starts only one server in a configurable port (default to 80 and 443) and proxies all traffic based on the from parameter patterns.

Alternative

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions