@stacksjs/rpx 0.11.4 → 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 +82 -0
- package/dist/bin/cli.js +243 -8
- package/dist/chunk-6z1nzq0x.js +1 -0
- package/dist/chunk-jpf41gb9.js +49 -0
- package/dist/chunk-qcdcnadb.js +1 -0
- package/dist/daemon-runner.d.ts +29 -0
- package/dist/daemon.d.ts +99 -0
- package/dist/https.d.ts +8 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +155 -0
- package/dist/process-manager.d.ts +1 -0
- package/dist/proxy-handler.d.ts +15 -0
- package/dist/registry.d.ts +74 -0
- package/dist/start.d.ts +3 -0
- package/dist/types.d.ts +2 -0
- package/dist/utils.d.ts +13 -1
- package/package.json +11 -9
- package/src/daemon-runner.ts +148 -0
- package/src/daemon.ts +496 -0
- package/src/https.ts +105 -64
- package/src/index.ts +42 -0
- package/src/process-manager.ts +2 -2
- package/src/proxy-handler.ts +99 -0
- package/src/registry.ts +346 -0
- package/src/start.ts +66 -84
- package/src/types.ts +21 -1
- package/src/utils.ts +78 -1
- package/dist/chunk-3y886wa5.js +0 -1
- package/dist/chunk-61re8msk.js +0 -1
- package/dist/chunk-94pvxvt5.js +0 -1
- package/dist/chunk-dz3837t8.js +0 -45
- package/dist/chunk-g5db14m7.js +0 -19
- package/dist/chunk-gbny098p.js +0 -2
- package/dist/chunk-pbbtnqsx.js +0 -123
- package/dist/dns.d.ts +0 -21
- package/dist/src/index.js +0 -1
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.
|