Skip to content

Commit 1a4a640

Browse files
committed
docs: document Request Inspector in README
Adds inspector config option table to Configuration Options and a new Request Inspector section covering the web UI, source badges (P/C/L), DevTools console banner, REST API endpoints, and configuration example.
1 parent 14ab407 commit 1a4a640

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@ module.exports = defineConfig({
175175
| `versionFile` | `boolean \| { enabled?: boolean; fileNameTemplate?: string }` | `true` | Write a VERSION file into the build |
176176
| `imageOptimisations`| `boolean \| Record<string, unknown>` | `true` | Image optimization. See [vite-plugin-image-optimizer](https://www.npmjs.com/package/vite-plugin-image-optimizer#plugin-options) for object options |
177177

178+
### `inspector` — Request Inspector
179+
180+
| Field | Type | Default | Description |
181+
|----------------|-----------|-------------|----------------------------------------------------------------|
182+
| `enabled` | `boolean` | `true` | Enable the request inspector |
183+
| `maxMemory` | `number` | `104857600` | Max total body memory (bytes) before oldest entries are evicted (default 100 MB) |
184+
| `captureLimit` | `number` | `10485760` | Max body size captured per request/response (bytes, default 10 MB). Larger bodies are stored truncated. |
185+
178186
### `sync` — Template sync
179187

180188
| Field | Type | Default | Description |
@@ -380,6 +388,68 @@ module.exports = withPPDev({
380388

381389
For custom build configuration, create a `vite.config` file. See [Vite Configuration](https://vitejs.dev/config/) for details.
382390

391+
## Request Inspector
392+
393+
pp-dev includes a built-in request inspector that captures every proxied and locally-served HTTP request made during development. It is enabled by default.
394+
395+
### Web UI
396+
397+
Open `http://localhost:3000/@pp-dev/inspector` (replace port as needed) in any browser tab while the dev server is running. The UI shows:
398+
399+
- A scrollable list of captured requests with method, status, source badge, and timing
400+
- Full request and response headers, with a **Copy** button per section
401+
- Request and response bodies rendered as text for JSON/HTML/CSS/plain-text content types, with **Copy** and **Save** buttons
402+
- Binary bodies (images, fonts, archives) show metadata only and offer a **Save** button
403+
- A **Clear** button in the top-right removes all stored entries
404+
405+
### Source badges
406+
407+
Each request in the list displays a colored letter badge to the left of the HTTP status:
408+
409+
| Badge | Color | Meaning |
410+
|-------|--------|----------------------------------------------|
411+
| `P` | Purple | Forwarded to the upstream Metric Insights server (proxy) |
412+
| `C` | Amber | Served from the local proxy cache |
413+
| `L` | Grey | Served locally (static file, dev route, etc.) |
414+
415+
### Console banner
416+
417+
The dev panel script prints a one-line banner to the browser DevTools console when the page loads:
418+
419+
```
420+
pp-dev 🔍 Request Inspector → http://localhost:3000/@pp-dev/inspector
421+
```
422+
423+
The message persists in DevTools history so it is visible even when you open the console after the page has loaded.
424+
425+
### REST API
426+
427+
The inspector also exposes a lightweight JSON API, useful for tooling and AI agents:
428+
429+
| Method | Path | Description |
430+
|----------|-------------------------|---------------------------------------------|
431+
| `GET` | `/@api/requests` | Paginated list of captured requests (metadata only, no bodies) |
432+
| `GET` | `/@api/requests/:id` | Full entry including captured request/response bodies (base64-encoded) |
433+
| `GET` | `/@api/requests/stats` | Store stats: entry count, memory usage, limits |
434+
| `DELETE` | `/@api/requests` | Clear all stored entries |
435+
436+
`GET /@api/requests` accepts `?limit=` (default 50) and `?offset=` query parameters for pagination.
437+
438+
Bodies in `GET /@api/requests/:id` are returned as base64 strings in `requestBody` / `responseBody` fields alongside `requestContentType` / `responseContentType`. A `*Truncated: true` flag indicates the body exceeded `captureLimit` and was cut off.
439+
440+
### Configuration
441+
442+
```typescript
443+
// pp-dev.config.ts
444+
export default defineConfig({
445+
inspector: {
446+
enabled: true, // set to false to disable entirely
447+
maxMemory: 100 * 1024 * 1024, // evict oldest entries above 100 MB
448+
captureLimit: 10 * 1024 * 1024, // capture at most 10 MB per body
449+
},
450+
});
451+
```
452+
383453
## Troubleshooting
384454

385455
### Common Issues

0 commit comments

Comments
 (0)