@stacksjs/rpx 0.11.20 → 0.11.22

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.
@@ -0,0 +1,56 @@
1
+ import type { RegistryEntry } from './registry';
2
+ import type { SiteResolver } from './site-resolver';
3
+ /** A launched site process, abstracted so tests can inject a fake. */
4
+ export declare interface SiteProcessHandle {
5
+ pid: number
6
+ exited: Promise<number | null>
7
+ stop: (signal?: NodeJS.Signals) => void
8
+ }
9
+ /** A point-in-time view of one supervised site, for `rpx sites` / status. */
10
+ export declare interface SiteSnapshot {
11
+ host: string
12
+ dir: string
13
+ status: 'starting' | 'ready' | 'failed'
14
+ pid: number | null
15
+ ports: Record<string, number>
16
+ uptimeMs: number
17
+ idleMs: number
18
+ error?: string
19
+ }
20
+ export declare interface SiteSupervisorOptions {
21
+ resolver: SiteResolver
22
+ registryDir?: string
23
+ rpxDir?: string
24
+ verbose?: boolean
25
+ startupTimeoutMs?: number
26
+ pollIntervalMs?: number
27
+ reapIntervalMs?: number
28
+ restartDelayMs?: number
29
+ killGraceMs?: number
30
+ launcher?: SiteLauncher
31
+ probePort?: (port: number) => Promise<boolean>
32
+ pickPort?: (preferred: number) => Promise<number>
33
+ isHostRoutable?: (host: string) => boolean
34
+ onSiteActivating?: (host: string) => void
35
+ now?: () => number
36
+ writeEntry?: (entry: RegistryEntry, dir?: string, verbose?: boolean) => Promise<void>
37
+ removeEntry?: (id: string, dir?: string, verbose?: boolean) => Promise<void>
38
+ }
39
+ /** Spawn a site's dev command. Injected for tests; default spawns a shell. */
40
+ export type SiteLauncher = (spec: {
41
+ command: string
42
+ cwd: string
43
+ env: Record<string, string>
44
+ logPath: string
45
+ }) => SiteProcessHandle;
46
+ export type SiteRequestStatus = | { kind: 'unknown' }
47
+ | { kind: 'starting', host: string, sinceMs: number, source: 'config' | 'discovered', logTail: string }
48
+ | { kind: 'ready', host: string }
49
+ | { kind: 'failed', host: string, error: string, logTail: string }
50
+ export declare class SiteSupervisor {
51
+ constructor(opts: SiteSupervisorOptions);
52
+ onRequest(host: string): Promise<SiteRequestStatus>;
53
+ stop(host: string): Promise<void>;
54
+ list(): SiteSnapshot[];
55
+ stopAll(): Promise<void>;
56
+ }
package/dist/start.d.ts CHANGED
@@ -6,7 +6,7 @@ import type { SniTlsEntry } from './sni';
6
6
  export declare function cleanup(options?: CleanupOptions): Promise<void>;
7
7
  export declare function startServer(options: SingleProxyConfig): Promise<void>;
8
8
  export declare function setupProxy(options: ProxySetupOptions): Promise<void>;
9
- export declare function startHttpRedirectServer(verbose?: boolean, httpPort?: number, httpsPort?: number): void;
9
+ export declare function startHttpRedirectServer(verbose?: boolean, httpPort?: number, httpsPort?: number, acmeChallengeWebroot?: string): void;
10
10
  export declare function startProxy(options: ProxyOption): void;
11
11
  export declare function startProxies(options?: ProxyOptions): Promise<void>;
12
12
  /**
package/dist/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { OriginGuardOptions } from './origin-guard';
2
+ import type { RedirectRouteConfig } from './redirect';
2
3
  import type { TlsConfig, TlsOption } from '@stacksjs/tlsx';
3
4
  export type { TlsConfig, TlsOption };
4
5
  export declare interface StartOptions {
@@ -17,13 +18,28 @@ export declare interface StaticRouteConfig {
17
18
  pathRewriteStyle?: PathRewriteStyle
18
19
  maxAge?: number
19
20
  }
21
+ /**
22
+ * HTTP Basic auth for a single route. When set, rpx challenges every request to
23
+ * the route with `401`/`WWW-Authenticate` until valid credentials are supplied
24
+ * (proxy, static, and WebSocket transports are all gated). Credentials may be
25
+ * given inline, as a `users[]` list, and/or via an Apache `htpasswd` file.
26
+ */
27
+ export declare interface BasicAuthConfig {
28
+ realm?: string
29
+ username?: string
30
+ password?: string
31
+ users?: Array<{ username: string, password: string }>
32
+ htpasswdFile?: string
33
+ }
20
34
  export declare interface BaseProxyConfig {
21
35
  from?: string
22
36
  to: string
37
+ auth?: BasicAuthConfig
23
38
  path?: string
24
39
  start?: StartOptions
25
40
  pathRewrites?: PathRewrite[]
26
41
  static?: string | StaticRouteConfig
42
+ redirect?: string | RedirectRouteConfig
27
43
  id?: string
28
44
  }
29
45
  export declare interface CleanupConfig {
@@ -79,6 +95,49 @@ export declare interface OnDemandTlsConfig {
79
95
  staging?: boolean
80
96
  certsDir?: string
81
97
  }
98
+ /**
99
+ * One backend a site exposes, mapped to a request path. rpx picks a free port,
100
+ * exports it to the dev command via {@link portEnv}, and proxies {@link path}
101
+ * (under the site host) to `localhost:<port>`.
102
+ *
103
+ * A Stacks app, for example, has three: the frontend at `/` (env `PORT`), the
104
+ * API at `/api` (env `PORT_API`), and the docs at `/docs` (env `PORT_DOCS`).
105
+ */
106
+ export declare interface SiteRouteTemplate {
107
+ path?: string
108
+ portEnv: string
109
+ defaultPort?: number
110
+ stripPrefix?: boolean
111
+ readyGate?: boolean
112
+ }
113
+ /**
114
+ * A lazily-booted project. The first request to {@link to} starts {@link command}
115
+ * in {@link dir}; rpx holds the request behind a "starting…" splash until the
116
+ * site's ready gate passes, then proxies it. After {@link idleTimeoutMs} with no
117
+ * traffic the process is stopped again — so a machine can "have" dozens of sites
118
+ * but only run the ones in active use.
119
+ */
120
+ export declare interface SiteConfig {
121
+ to: string
122
+ dir: string
123
+ command: string
124
+ env?: Record<string, string>
125
+ routes?: SiteRouteTemplate[]
126
+ selfRegisters?: boolean
127
+ idleTimeoutMs?: number
128
+ }
129
+ /**
130
+ * On-demand sites: lazily boot a project's dev server the first time its host is
131
+ * visited, then proxy to it (Valet/puma-dev style). Opt-in via {@link enabled}.
132
+ */
133
+ export declare interface OnDemandSitesConfig {
134
+ enabled?: boolean
135
+ sites?: SiteConfig[]
136
+ roots?: string[]
137
+ tlds?: string[]
138
+ idleTimeoutMs?: number
139
+ startupTimeoutMs?: number
140
+ }
82
141
  export declare interface SharedProxyConfig {
83
142
  https: boolean | TlsOption
84
143
  cleanup: boolean | CleanupOptions
@@ -92,10 +151,12 @@ export declare interface SharedProxyConfig {
92
151
  singlePortMode?: boolean
93
152
  httpPort?: number
94
153
  httpsPort?: number
154
+ acmeChallengeWebroot?: string
95
155
  viaDaemon?: boolean
96
156
  hostsManagement?: boolean
97
157
  productionCerts?: ProductionTlsConfig
98
158
  onDemandTls?: OnDemandTlsConfig
159
+ onDemand?: OnDemandSitesConfig
99
160
  originGuard?: OriginGuardOptions
100
161
  }
101
162
  export declare interface SingleProxyConfig extends BaseProxyConfig, SharedProxyConfig {}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/rpx",
3
3
  "type": "module",
4
- "version": "0.11.20",
4
+ "version": "0.11.22",
5
5
  "description": "A modern and smart reverse proxy.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",