@stacksjs/rpx 0.11.5 → 0.11.7

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
@@ -130,6 +130,88 @@ rpx --help
130
130
  rpx --version
131
131
  ```
132
132
 
133
+ ## Daemon mode (shared `:443` for multiple apps)
134
+
135
+ By default, every `rpx start` binds its own `:443`. That works for one app at a
136
+ time. If you want **several local apps reachable concurrently** at
137
+ `https://<app>.localhost` — Valet-style — run them through the rpx daemon
138
+ instead.
139
+
140
+ The daemon is a single long-running process that owns `:443` + `:80`, holds the
141
+ shared Root CA, and routes traffic per a small file-based registry under
142
+ `~/.stacks/rpx/`. Each `rpx register` (or `rpx start --via-daemon`) drops one
143
+ JSON file into the registry; the daemon hot-reloads its routing table on
144
+ change.
145
+
146
+ ### Quick start
147
+
148
+ ```bash
149
+ # Lazy-spawns the daemon if it isn't running, then registers your app
150
+ # Survives across sessions until you `unregister` or kill the daemon
151
+ rpx register --id pet-store --from localhost:5173 --to pet-store.localhost
152
+ rpx register --id training --from localhost:5174 --to training.localhost
153
+
154
+ # Inspect what the daemon is routing right now
155
+ rpx daemon:status
156
+ # rpx daemon: running (pid=12345)
157
+ # registered hosts (2)
158
+ # - https://pet-store.localhost -> localhost:5173 (id=pet-store, ...)
159
+ # - https://training.localhost -> localhost:5174 (id=training, ...)
160
+
161
+ # Remove an app
162
+ rpx unregister pet-store
163
+
164
+ # Stop the daemon entirely
165
+ rpx daemon:stop
166
+ ```
167
+
168
+ ### `rpx start --via-daemon`
169
+
170
+ If you'd rather keep the familiar `rpx start` flow but participate in the
171
+ shared `:443` server, opt in with `--via-daemon`:
172
+
173
+ ```bash
174
+ rpx start --from localhost:5173 --to pet-store.localhost --via-daemon
175
+ ```
176
+
177
+ This registers an entry, spawns/attaches the daemon, prints the URL, and
178
+ unregisters when you Ctrl+C — so two `rpx start --via-daemon` invocations no
179
+ longer fight over `:443`.
180
+
181
+ The same flag is available as a config option (`viaDaemon: true`) and can be
182
+ set per-proxy or at the top level of `rpx.config.ts`.
183
+
184
+ ### What lives where
185
+
186
+ | Path | What |
187
+ | --------------------------------- | -------------------------------------------------------------------- |
188
+ | `~/.stacks/rpx/daemon.pid` | Single-instance lock (atomic `O_CREAT \| O_EXCL`) |
189
+ | `~/.stacks/rpx/registry.d/<id>.json` | One file per registered app |
190
+ | Root CA (via `@stacksjs/tlsx`) | Persisted between regens; trust prompt happens once, not per app |
191
+
192
+ The daemon GCs entries whose writer PID is dead, so `kill -9` on a dev server
193
+ cleans itself up within a few seconds.
194
+
195
+ ### Library API
196
+
197
+ ```ts
198
+ import { ensureDaemonRunning, runViaDaemon, stopDaemon } from '@stacksjs/rpx'
199
+
200
+ // Register one or more proxies and ensure the daemon is up.
201
+ await runViaDaemon({
202
+ proxies: [
203
+ { id: 'pet-store', from: 'localhost:5173', to: 'pet-store.localhost' },
204
+ { id: 'training', from: 'localhost:5174', to: 'training.localhost', cleanUrls: true },
205
+ ],
206
+ })
207
+
208
+ // Or just make sure the daemon is running, without registering anything.
209
+ const { pid, spawned } = await ensureDaemonRunning()
210
+
211
+ // Shut it down.
212
+ await stopDaemon()
213
+ ```
214
+
133
215
  ## Configuration
134
216
 
135
217
  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.