@chaiops/n-ext 0.0.1-alpha โ 0.0.3-alpha
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 +315 -0
- package/package.json +8 -4
package/README.md
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
# ๐ n-ext
|
|
2
|
+
|
|
3
|
+
[](https://github.com/chaiops/n-ext/releases/latest)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
Next.js Server DevTools โ capture and inspect server-side network requests (fetch & http) from your Next.js app in a Chrome DevTools panel.
|
|
7
|
+
|
|
8
|
+
> โ ๏ธ **Development only.** n-ext is designed exclusively for local development. It does not ship to production, adds zero runtime overhead to production builds, and refuses to start if `NODE_ENV=production`. Think of it like React DevTools โ a transparent layer that exists only while you're building.
|
|
9
|
+
|
|
10
|
+
<p align="center">
|
|
11
|
+
<img src="docs/screenshot-01.png" width="49%" alt="n-ext request list view" />
|
|
12
|
+
<img src="docs/screenshot-02.png" width="49%" alt="n-ext request detail view" />
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
## ๐ Getting started
|
|
16
|
+
|
|
17
|
+
Just replace `next` with `n-ext` in your dev command โ that's it, you get a full network inspector for Next.js.
|
|
18
|
+
|
|
19
|
+
### 1. Run
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx @chaiops/n-ext dev
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or install as a dev dependency:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @chaiops/n-ext --save-dev
|
|
29
|
+
# or
|
|
30
|
+
pnpm add -D @chaiops/n-ext
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 2. Update your dev script
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
{
|
|
37
|
+
"scripts": {
|
|
38
|
+
"dev": "n-ext dev"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
All arguments are forwarded to `next dev`:
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"scripts": {
|
|
48
|
+
"dev": "n-ext dev --port 3099 --turbopack"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 3. Install the Chrome extension
|
|
54
|
+
|
|
55
|
+
1. Download [`n-ext-chrome-v0.0.3-alpha.zip`](https://github.com/chaiops/n-ext/releases/download/ext-v0.0.3-alpha/n-ext-chrome-v0.0.3-alpha.zip) or grab the latest from [GitHub Releases](https://github.com/chaiops/n-ext/releases/latest)
|
|
56
|
+
2. Unzip the downloaded file
|
|
57
|
+
3. Open `chrome://extensions` and enable **Developer mode**
|
|
58
|
+
4. Click **Load unpacked** and select the unzipped folder
|
|
59
|
+
5. Open DevTools on your app โ you'll see a **๐ต n-ext** tab
|
|
60
|
+
|
|
61
|
+
### 4. Run your app
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npm run dev
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
You should see:
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
[n-ext] DevTools server running at http://127.0.0.1:3894/see
|
|
71
|
+
[n-ext] Interceptors installed (server mode)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Open your app in Chrome, open DevTools, and switch to the **๐ต n-ext** tab to see captured server-side requests.
|
|
75
|
+
|
|
76
|
+
## โจ Features
|
|
77
|
+
|
|
78
|
+
| Feature | Details |
|
|
79
|
+
|---|---|
|
|
80
|
+
| **Automatic interception** | Captures `fetch`, `http.request`, and `https.request` โ no code changes needed |
|
|
81
|
+
| **Chrome DevTools panel** | Dedicated **๐ต n-ext** tab with request list, headers, body preview, and timing |
|
|
82
|
+
| **JSON tree preview** | Collapsible JSON viewer for request and response bodies |
|
|
83
|
+
| **Method & URL filtering** | Filter by HTTP method (GET, POST, PUT, DELETE) and URL pattern |
|
|
84
|
+
| **Request details** | View request/response headers, bodies, status codes, duration, and size |
|
|
85
|
+
| **Copy to clipboard** | One-click copy for request and response bodies (auto-formatted JSON) |
|
|
86
|
+
| **Copy as cURL** | Export any captured request as a ready-to-run cURL command |
|
|
87
|
+
| **Cursor-based polling** | Efficient incremental updates โ only fetches new events |
|
|
88
|
+
| **Ring buffer storage** | Keeps the last 1000 events in memory with zero disk I/O |
|
|
89
|
+
| **Development only** | Refuses to start if `NODE_ENV=production` โ zero production impact |
|
|
90
|
+
| **Zero config** | No middleware, no config files โ just replace `next` with `n-ext` |
|
|
91
|
+
| **Local only** | Listens on `127.0.0.1:3894` โ never exposed to the network |
|
|
92
|
+
| **Dual source tracking** | Labels each request as `fetch` or `http` so you know the origin |
|
|
93
|
+
|
|
94
|
+
## ๐ฎ Future Scope
|
|
95
|
+
|
|
96
|
+
- **MCP server** โ Expose captured requests via Model Context Protocol so AI tools (Cursor, Claude Code) can read and reason about your server's network traffic
|
|
97
|
+
- **CLI viewer** โ Terminal-based UI for inspecting requests without opening Chrome (`n-ext --tui`)
|
|
98
|
+
|
|
99
|
+
## ๐ก Why
|
|
100
|
+
|
|
101
|
+
Next.js server components, server actions, and route handlers make API calls that are **invisible** to the browser's Network tab. You're left with a few options, none of them great:
|
|
102
|
+
|
|
103
|
+
| Approach | Problem |
|
|
104
|
+
|---|---|
|
|
105
|
+
| **Node.js debugger** | You're juggling two separate debugger windows (browser + Node) and it lacks the filtering/visualization of Chrome DevTools |
|
|
106
|
+
| **`console.log`** | You have to litter your code with logging statements and clean them up later |
|
|
107
|
+
| **`process.env.NODE_ENV` / `isDevelopment` guards** | You're changing application code just to get dev-only observability |
|
|
108
|
+
|
|
109
|
+
All of these share the same fundamental issue: **they require you to modify your application code** to see what your server is doing.
|
|
110
|
+
|
|
111
|
+
What we actually want is a **transparent dev-only layer** โ something that captures every server-side fetch and http call automatically, without touching your application code, and shows it right in Chrome DevTools. Like React DevTools, but for your server's network traffic.
|
|
112
|
+
|
|
113
|
+
`n-ext` does exactly that. Replace `next dev` with `n-ext dev` and you get a Chrome DevTools panel showing every outgoing request your server makes โ method, URL, status, headers, body, timing โ with **zero code changes** and **zero production impact**.
|
|
114
|
+
|
|
115
|
+
## ๐๏ธ Architecture
|
|
116
|
+
|
|
117
|
+
```mermaid
|
|
118
|
+
---
|
|
119
|
+
config:
|
|
120
|
+
layout: elk
|
|
121
|
+
---
|
|
122
|
+
flowchart TD
|
|
123
|
+
subgraph Your Next.js App
|
|
124
|
+
A[next dev] -->|spawned by| CLI["n-ext CLI"]
|
|
125
|
+
SC[Server Components<br>Server Actions<br>Route Handlers] -->|fetch / http.request| INT
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
subgraph "n-ext Runtime <br><i>injected via NODE_OPTIONS=--require</i>"
|
|
129
|
+
INT[Interceptors<br>fetch ยท http ยท https] -->|capture event| STORE[Event Store<br>in-memory ring buffer]
|
|
130
|
+
STORE --> SEE["/see HTTP Server<br>:3894"]
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
subgraph Chrome Browser
|
|
134
|
+
EXT["n-ext DevTools Panel"] -->|poll GET /see?cursor=N| SEE
|
|
135
|
+
EXT -->|POST /clear| SEE
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
style CLI fill:#f0f0f0,stroke:#333
|
|
139
|
+
style INT fill:#e8f4e8,stroke:#2d7d2d
|
|
140
|
+
style STORE fill:#e8f4e8,stroke:#2d7d2d
|
|
141
|
+
style SEE fill:#e8f4e8,stroke:#2d7d2d
|
|
142
|
+
style EXT fill:#e0ecff,stroke:#2563eb
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Data flow:**
|
|
146
|
+
|
|
147
|
+
1. **`n-ext dev`** spawns `next dev` with `NODE_OPTIONS=--require register.js`, injecting interceptors into the Node.js process before any app code runs
|
|
148
|
+
2. **Interceptors** monkey-patch `globalThis.fetch`, `http.request`, and `https.request` โ every outgoing request is captured with method, URL, headers, body, status, timing, and size
|
|
149
|
+
3. **Event Store** holds the last 1000 events in a ring buffer with monotonic cursors for efficient polling
|
|
150
|
+
4. **`/see` server** (port 3894) serves events as JSON โ the Chrome extension polls `GET /see?cursor=N` every 500ms to get only new events
|
|
151
|
+
5. **Chrome DevTools panel** renders a network-inspector UI with filtering, detail views, and timing visualization
|
|
152
|
+
|
|
153
|
+
## โ๏ธ How it works
|
|
154
|
+
|
|
155
|
+
`n-ext` wraps `next dev` and injects runtime interceptors via `NODE_OPTIONS=--require`. It patches `globalThis.fetch`, `http.request`, and `https.request` to capture all outgoing server-side requests. Captured events are exposed on `http://localhost:3894/see` for the Chrome extension to consume.
|
|
156
|
+
|
|
157
|
+
**Key design decisions:**
|
|
158
|
+
|
|
159
|
+
- ๐ซ **No production code** โ the CLI exits immediately if `NODE_ENV=production`
|
|
160
|
+
- ๐งฉ **No app changes needed** โ interception happens at the runtime level via `--require`
|
|
161
|
+
- ๐ **Listens on `127.0.0.1` only** โ never exposed to the network
|
|
162
|
+
- ๐ชถ **Minimal footprint** โ a single `--require` flag, no middleware, no config files
|
|
163
|
+
|
|
164
|
+
## โ
Verify it works
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
# Check the event stream directly
|
|
168
|
+
curl http://localhost:3894/see
|
|
169
|
+
|
|
170
|
+
# With cursor-based pagination
|
|
171
|
+
curl http://localhost:3894/see?cursor=5
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Response format:
|
|
175
|
+
|
|
176
|
+
```json
|
|
177
|
+
{
|
|
178
|
+
"cursor": 10,
|
|
179
|
+
"events": [
|
|
180
|
+
{
|
|
181
|
+
"id": "uuid",
|
|
182
|
+
"url": "https://api.example.com/data",
|
|
183
|
+
"method": "GET",
|
|
184
|
+
"status": 200,
|
|
185
|
+
"duration": 123.4,
|
|
186
|
+
"source": "fetch",
|
|
187
|
+
...
|
|
188
|
+
}
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## ๐ Monorepo structure
|
|
194
|
+
|
|
195
|
+
```
|
|
196
|
+
packages/
|
|
197
|
+
n-ext/ CLI + runtime interceptors + /see server
|
|
198
|
+
extension/ Chrome DevTools extension
|
|
199
|
+
apps/
|
|
200
|
+
demo/ Example Next.js app
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## ๐ ๏ธ Development
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
pnpm install
|
|
207
|
+
pnpm build # build n-ext package
|
|
208
|
+
cd apps/demo && pnpm dev # run demo with n-ext
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Code style
|
|
212
|
+
|
|
213
|
+
- **EditorConfig** โ consistent indentation and encoding across editors (see `.editorconfig`)
|
|
214
|
+
- **Prettier** โ auto-format with `pnpm format`; config in `.prettierrc`
|
|
215
|
+
- **ESLint** โ lint with `pnpm lint`
|
|
216
|
+
- **TypeScript** โ strict mode enabled in `packages/n-ext`
|
|
217
|
+
|
|
218
|
+
### Commit conventions
|
|
219
|
+
|
|
220
|
+
We use [Conventional Commits](https://www.conventionalcommits.org/):
|
|
221
|
+
|
|
222
|
+
```
|
|
223
|
+
<type>(<scope>): <description>
|
|
224
|
+
|
|
225
|
+
feat(interceptor): add websocket support
|
|
226
|
+
fix(store): prevent cursor overflow on large event counts
|
|
227
|
+
docs(readme): add architecture diagram
|
|
228
|
+
chore(deps): bump tsup to v9
|
|
229
|
+
refactor(panel): extract header rendering logic
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
**Types:** `feat` ยท `fix` ยท `docs` ยท `chore` ยท `refactor` ยท `test` ยท `perf` ยท `ci`
|
|
233
|
+
|
|
234
|
+
**Scopes (optional):** `cli` ยท `interceptor` ยท `store` ยท `server` ยท `panel` ยท `extension` ยท `deps`
|
|
235
|
+
|
|
236
|
+
### Best practices
|
|
237
|
+
|
|
238
|
+
- Keep changes focused โ one concern per commit
|
|
239
|
+
- Run `pnpm build` before committing to make sure everything compiles
|
|
240
|
+
- Test with the demo app (`apps/demo`) before submitting changes
|
|
241
|
+
- Don't commit `dist/` โ it's gitignored and built in CI
|
|
242
|
+
|
|
243
|
+
## ๐ค Contributing
|
|
244
|
+
|
|
245
|
+
Contributions are welcome! Here's how to get started:
|
|
246
|
+
|
|
247
|
+
1. **Fork** the repo and clone your fork
|
|
248
|
+
2. **Install** dependencies: `pnpm install`
|
|
249
|
+
3. **Link locally** to test in a Next.js app:
|
|
250
|
+
```bash
|
|
251
|
+
cd packages/n-ext && pnpm build
|
|
252
|
+
# In your Next.js app
|
|
253
|
+
pnpm add -D /path/to/n-ext/packages/n-ext
|
|
254
|
+
```
|
|
255
|
+
This adds a `file:` dependency. After any changes, rebuild and reinstall:
|
|
256
|
+
```bash
|
|
257
|
+
cd /path/to/n-ext/packages/n-ext && pnpm build
|
|
258
|
+
cd /path/to/your-app && pnpm install
|
|
259
|
+
```
|
|
260
|
+
4. **Create a branch** from `main`:
|
|
261
|
+
```bash
|
|
262
|
+
git checkout -b feat/my-feature
|
|
263
|
+
```
|
|
264
|
+
5. **Make your changes** โ follow the code style and commit conventions above
|
|
265
|
+
6. **Build & test** locally:
|
|
266
|
+
```bash
|
|
267
|
+
pnpm build
|
|
268
|
+
cd apps/demo && pnpm dev
|
|
269
|
+
# Open Chrome DevTools โ n-ext tab and verify your changes
|
|
270
|
+
```
|
|
271
|
+
7. **Push** and open a pull request against `main`
|
|
272
|
+
|
|
273
|
+
### PR guidelines
|
|
274
|
+
|
|
275
|
+
- Keep PRs small and focused
|
|
276
|
+
- Describe *what* changed and *why* in the PR description
|
|
277
|
+
- Link any related issues
|
|
278
|
+
- Make sure the build passes (`pnpm build`)
|
|
279
|
+
|
|
280
|
+
### Building & publishing packages
|
|
281
|
+
|
|
282
|
+
**n-ext (npm package):**
|
|
283
|
+
```bash
|
|
284
|
+
cd packages/n-ext
|
|
285
|
+
pnpm build # compiles TypeScript to dist/
|
|
286
|
+
npm publish --access public # publish to npm as @chaiops/n-ext
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
**Chrome extension:**
|
|
290
|
+
```bash
|
|
291
|
+
cd packages/extension
|
|
292
|
+
pnpm build # builds to dist/ (includes README)
|
|
293
|
+
```
|
|
294
|
+
Then load the `dist/` folder in `chrome://extensions` with **Developer mode** enabled โ **Load unpacked**.
|
|
295
|
+
|
|
296
|
+
**Build all packages:**
|
|
297
|
+
```bash
|
|
298
|
+
pnpm build:all
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
> **Note:** Bump the version in the relevant `package.json` (and `manifest.json` for the extension) before publishing.
|
|
302
|
+
|
|
303
|
+
## ๐ฅ Contributors
|
|
304
|
+
|
|
305
|
+
<!-- ALL-CONTRIBUTORS-LIST:START -->
|
|
306
|
+
<a href="https://github.com/MananDesai54"><img src="https://github.com/MananDesai54.png" width="60px" alt="MananDesai54" style="border-radius:50%" /></a>
|
|
307
|
+
<a href="https://github.com/anuj-kosambi"><img src="https://github.com/anuj-kosambi.png" width="60px" alt="anuj-kosambi" style="border-radius:50%" /></a>
|
|
308
|
+
<a href="https://github.com/centerseat"><img src="https://github.com/centerseat.png" width="60px" alt="centerseat" style="border-radius:50%" /></a>
|
|
309
|
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
310
|
+
|
|
311
|
+
Built with โค๏ธ in India ๐ฎ๐ณ
|
|
312
|
+
|
|
313
|
+
## ๐ License
|
|
314
|
+
|
|
315
|
+
[MIT](LICENSE)
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chaiops/n-ext",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3-alpha",
|
|
4
4
|
"description": "Next.js Server DevTools โ capture and inspect server-side network requests",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Anuj",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/chaiops/n-ext"
|
|
9
|
+
"url": "git+https://github.com/chaiops/n-ext.git",
|
|
10
|
+
"directory": "packages/n-ext"
|
|
10
11
|
},
|
|
11
12
|
"keywords": [
|
|
12
13
|
"nextjs",
|
|
@@ -24,13 +25,16 @@
|
|
|
24
25
|
"./runtime/register": "./dist/runtime/register.js"
|
|
25
26
|
},
|
|
26
27
|
"files": [
|
|
27
|
-
"dist"
|
|
28
|
+
"dist",
|
|
29
|
+
"README.md"
|
|
28
30
|
],
|
|
31
|
+
"homepage": "https://github.com/chaiops/n-ext#readme",
|
|
32
|
+
"bugs": "https://github.com/chaiops/n-ext/issues",
|
|
29
33
|
"publishConfig": {
|
|
30
34
|
"access": "public"
|
|
31
35
|
},
|
|
32
36
|
"scripts": {
|
|
33
|
-
"build": "tsup",
|
|
37
|
+
"build": "tsup && cp ../../README.md README.md",
|
|
34
38
|
"dev": "tsup --watch"
|
|
35
39
|
},
|
|
36
40
|
"devDependencies": {
|