next-fetch-inspector 0.0.0-stage → 0.4.0
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/CHANGELOG.md +35 -0
- package/LICENSE +21 -0
- package/README.ar.md +87 -0
- package/README.md +223 -2
- package/SECURITY.md +15 -0
- package/docs/configuration.md +115 -0
- package/docs/dashboard.md +72 -0
- package/docs/faq.md +43 -0
- package/docs/getting-started.md +97 -0
- package/docs/how-it-works.md +58 -0
- package/docs/security.md +70 -0
- package/docs/testing.md +90 -0
- package/llms.txt +25 -0
- package/package.json +80 -4
- package/src/auth.js +83 -0
- package/src/core.js +661 -0
- package/src/format.js +298 -0
- package/src/index.d.ts +24 -0
- package/src/index.js +16 -0
- package/src/logger.js +122 -0
- package/src/redact.js +168 -0
- package/src/register.d.ts +1 -0
- package/src/register.js +17 -0
- package/src/route.d.ts +2 -0
- package/src/route.js +124 -0
- package/src/sourcemap.js +150 -0
- package/src/types.d.ts +87 -0
- package/src/ui.js +255 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.4.0: first public release
|
|
4
|
+
|
|
5
|
+
**Inspect**
|
|
6
|
+
- Every server-side `fetch()` in Server Components, Route Handlers, Server Actions and `generateMetadata`: method, URL, status, duration, request and response headers and bodies.
|
|
7
|
+
- The `file:line` that made the call (source maps under Turbopack; the file under webpack).
|
|
8
|
+
- Next.js cache awareness: `⚡ served by the Next.js cache`.
|
|
9
|
+
- Hints for common mistakes:
|
|
10
|
+
- JSON without `Content-Type`
|
|
11
|
+
- relative URLs on the server
|
|
12
|
+
- HTML instead of JSON
|
|
13
|
+
- lowercase `patch`
|
|
14
|
+
- redirects
|
|
15
|
+
- `ECONNREFUSED`, DNS, TLS and timeouts
|
|
16
|
+
- bodies over `maxBodySize`
|
|
17
|
+
|
|
18
|
+
**Dashboard** (`/fetch-inspector`)
|
|
19
|
+
- Real values, like the browser's Network tab, so **Copy cURL** reproduces requests exactly.
|
|
20
|
+
- **Copy redacted**, **Hide secrets**, and **Export HAR**, sanitized or with secrets.
|
|
21
|
+
- Filters, keyboard navigation, Pause / Resume, Clear, dark mode.
|
|
22
|
+
- Private link with a token kept in the browser tab (no cookies).
|
|
23
|
+
|
|
24
|
+
**Terminal**
|
|
25
|
+
- `full`, `summary` or `curl` output. Secrets are masked by default, and CI defaults to `summary`.
|
|
26
|
+
|
|
27
|
+
**Options**
|
|
28
|
+
- `maxEntries` (default 50), `maxBodySize`, `bodyTimeoutMs`, `ignore`, `redact*`, `onEntry`, `dashboardToken`, `dashboardHosts`, `dashboardPath`, `allowInProduction`.
|
|
29
|
+
- Environment variables: `NEXT_FETCH_INSPECTOR`, `NEXT_FETCH_INSPECTOR_LOG`, `NEXT_FETCH_INSPECTOR_TOKEN`.
|
|
30
|
+
|
|
31
|
+
**Compatibility**
|
|
32
|
+
- Next.js 13.4 → 16 (including `cacheComponents`), Turbopack and webpack, Node.js ≥ 20.9. Zero dependencies.
|
|
33
|
+
|
|
34
|
+
**Quality**
|
|
35
|
+
- 42 automated tests, plus end-to-end checks on Next.js 16.4. See [docs/testing.md](./docs/testing.md) and [docs/security.md](./docs/security.md).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 next-fetch-inspector contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.ar.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<div dir="rtl">
|
|
2
|
+
|
|
3
|
+
# next-fetch-inspector: الـ Network tab بتاع السيرفر في Next.js
|
|
4
|
+
|
|
5
|
+
**next-fetch-inspector باكدج للـ development بس، بتوريك كل `fetch()` بيعملها السيرفر في مشروع Next.js، بالطلب والرد وأمر cURL جاهز.** ده بيشمل الـ Server Components والـ Route Handlers والـ Server Actions، ودول كلهم مبيظهروش في الـ Network tab بتاع المتصفح.
|
|
6
|
+
|
|
7
|
+
بتلاقي كل ده في الترمينال وفي dashboard على جهازك. انسخ الـ request كـ cURL وابعته للـ backend dev، وهو يعيد المشكلة عنده في ثانية.
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
**جربها في دقيقة:** [الـ Playground](https://github.com/AhmedNnasser11/next-fetch-inspector-playground). مشروع Next.js 16 جاهز، فيه API وهمي و21 زرار GET / POST / PUT / PATCH / DELETE، منهم حالات نجاح وحالات خطأ.
|
|
12
|
+
|
|
13
|
+
## المشكلة
|
|
14
|
+
|
|
15
|
+
الـ `fetch()` اللي في الـ Server Component بيتنفذ في Node.js مش في المتصفح، فالـ DevTools مبيشوفوش. والـ `logging.fetches` اللي جاية مع Next.js بتطبع الـ URL بس.
|
|
16
|
+
|
|
17
|
+
## المميزات
|
|
18
|
+
|
|
19
|
+
- كل request على السيرفر بالـ headers والـ body، للطلب والرد.
|
|
20
|
+
- **الملف والسطر** اللي عمل الـ request، زي `app/page.tsx:9:23`.
|
|
21
|
+
- **Copy cURL** بالـ tokens الحقيقية، عشان الـ request يتعاد زي ما هو بالظبط.
|
|
22
|
+
- **Copy redacted** نسخة متخبية تحطها في أي مكان عام.
|
|
23
|
+
- بتقولك لو الرد جه من **كاش Next.js**.
|
|
24
|
+
- تنبيهات للأخطاء المشهورة: نسيان الـ Content-Type، والـ URL النسبي، والـ HTML بدل JSON، و`patch` الـ lowercase، والـ ECONNREFUSED، والـ timeout.
|
|
25
|
+
- Dashboard فيه فلترة وPause/Resume وHide secrets وdark mode، وتصدير HAR بطريقتين: متخبي أو بالقيم الحقيقية.
|
|
26
|
+
- شغالة في الـ dev بس، والـ dashboard بيرجع 404 في الـ production دايماً.
|
|
27
|
+
- من غير أي dependencies.
|
|
28
|
+
|
|
29
|
+
## التركيب
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm i -D next-fetch-inspector
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**1. في `instrumentation.ts`:**
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
export async function register() {
|
|
39
|
+
if (process.env.NODE_ENV === 'development') {
|
|
40
|
+
await import('next-fetch-inspector/register')
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**2. (اختياري) الـ Dashboard:**
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
// app/fetch-inspector/route.ts
|
|
49
|
+
export { GET, POST } from 'next-fetch-inspector/route'
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
أول ما `next dev` يشتغل، هيطبعلك لينك خاص فيه `#token=…`. افتحه وهتلاقي الـ requests بتاعتك. الـ token بيفضل في التاب دي بس، فلو فتحت تاب جديدة افتح اللينك تاني. اللينك نفسه مبيتغيرش، فتقدر تعمله bookmark.
|
|
53
|
+
|
|
54
|
+
> متسميش الفولدر بحاجة بتبدأ بـ `_`، ومتضيفش `export const dynamic`.
|
|
55
|
+
|
|
56
|
+
## الترمينال
|
|
57
|
+
|
|
58
|
+

|
|
59
|
+
|
|
60
|
+
## Copy cURL
|
|
61
|
+
|
|
62
|
+

|
|
63
|
+
|
|
64
|
+
## الأمان
|
|
65
|
+
|
|
66
|
+
- الـ dashboard بيعرض القيم الحقيقية زي الـ Network tab، وبيفتح باللينك الخاص بس. مفيش cookies، فمحدش غيرك يقدر يقرا الداتا: لا scripts تانية على `localhost`، ولا مواقع تانية، ولا أجهزة على نفس الشبكة.
|
|
67
|
+
- الترمينال وتصدير الـ HAR العادي و"Copy redacted" بيخبوا الأسرار.
|
|
68
|
+
- الـ cURL آمن تلصقه في الترمينال، وبيعيد الـ request بس.
|
|
69
|
+
- كل حماية ليها تست: [docs/security.md](./docs/security.md).
|
|
70
|
+
|
|
71
|
+
## Pause / Resume
|
|
72
|
+
|
|
73
|
+
بيوقفوا التسجيل ويرجعوه. الـ requests نفسها بتفضل شغالة عادي، بس مبتتسجلش. ولما يكون واقف، هتلاقي شريط أصفر في الـ dashboard وسطر في الترمينال.
|
|
74
|
+
|
|
75
|
+
## الذاكرة
|
|
76
|
+
|
|
77
|
+
الأداة بتحتفظ بآخر **50 request** في الذاكرة بس، ومبيتكتبش حاجة على الـ disk. تقدر تغير العدد بـ `install({ maxEntries: 100 })`.
|
|
78
|
+
|
|
79
|
+
## الشرح الكامل
|
|
80
|
+
|
|
81
|
+
[البداية](./docs/getting-started.md) · [الإعدادات](./docs/configuration.md) · [الـ Dashboard](./docs/dashboard.md) · [إزاي بتشتغل](./docs/how-it-works.md) · [التستات](./docs/testing.md) · [الأمان](./docs/security.md) · [أسئلة شائعة](./docs/faq.md)
|
|
82
|
+
|
|
83
|
+
## Credits
|
|
84
|
+
|
|
85
|
+
عملها [Ahmed Nasser](https://github.com/AhmedNnasser11) باستخدام **Claude Opus 5.5** من Anthropic: التصميم والكود ومراجعة الأمان والتستات.
|
|
86
|
+
|
|
87
|
+
</div>
|
package/README.md
CHANGED
|
@@ -1,3 +1,224 @@
|
|
|
1
|
-
#
|
|
1
|
+
# next-fetch-inspector: a Network tab for server-side fetch in Next.js
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/next-fetch-inspector)
|
|
4
|
+
[](https://github.com/AhmedNnasser11/next-fetch-inspector/actions/workflows/ci.yml)
|
|
5
|
+
[](./docs/testing.md)
|
|
6
|
+
[](https://nextjs.org)
|
|
7
|
+
[](./package.json)
|
|
8
|
+
[](./LICENSE)
|
|
9
|
+
|
|
10
|
+
**next-fetch-inspector is a development-only tool that shows every `fetch()` your Next.js server makes, with its request, response and a ready-to-run cURL command.** It covers Server Components, Route Handlers, Server Actions and `generateMetadata`, none of which show up in the browser's Network tab.
|
|
11
|
+
|
|
12
|
+
You get it in your terminal and in a local dashboard. Copy the exact request as cURL and send it to your backend developer, and they can reproduce the bug in one paste.
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
**Try it in 1 minute:** clone the [playground repo](https://github.com/AhmedNnasser11/next-fetch-inspector-playground). It's a Next.js 16 app with a mock API and 21 buttons for GET / POST / PUT / PATCH / DELETE, covering both success and error cases.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Contents
|
|
21
|
+
|
|
22
|
+
- [Why: the problem it solves](#why-the-problem-it-solves)
|
|
23
|
+
- [Features](#features)
|
|
24
|
+
- [Quick start](#quick-start)
|
|
25
|
+
- [Screenshots](#screenshots)
|
|
26
|
+
- [How it compares](#how-it-compares)
|
|
27
|
+
- [Configuration](#configuration)
|
|
28
|
+
- [Is it safe?](#is-it-safe)
|
|
29
|
+
- [FAQ](#faq)
|
|
30
|
+
- [Documentation](#documentation)
|
|
31
|
+
- [Credits](#credits)
|
|
32
|
+
|
|
33
|
+
## Why: the problem it solves
|
|
34
|
+
|
|
35
|
+
When a Next.js Server Component calls `fetch()`, the request runs in **Node.js**, not the browser. Chrome DevTools never sees it. When an API call fails on the server, you usually end up adding `console.log` everywhere to find out:
|
|
36
|
+
|
|
37
|
+
- What URL, headers and body were actually sent?
|
|
38
|
+
- What did the API answer?
|
|
39
|
+
- Did the request even reach the network, or did the **Next.js cache** answer it?
|
|
40
|
+
- How do I give the backend developer something they can run?
|
|
41
|
+
|
|
42
|
+
Next.js' built-in [`logging.fetches`](https://nextjs.org/docs/app/api-reference/config/next-config-js/logging) prints only the URL and cache status. `next dev --inspect` gives you a debugger but no Network tab for server requests. **next-fetch-inspector fills that gap.**
|
|
43
|
+
|
|
44
|
+
## Features
|
|
45
|
+
|
|
46
|
+
- **Every server-side `fetch()` captured**: method, URL, status, duration, request and response headers and bodies.
|
|
47
|
+
- **The file and line that made the call**, e.g. `app/page.tsx:9:23`, resolved through source maps under Turbopack.
|
|
48
|
+
- **Copy as cURL, exactly as sent.** Tokens, cookies and body are included, so the request can be reproduced 1:1.
|
|
49
|
+
- **Copy redacted.** The same cURL with secrets masked, for issues and chat.
|
|
50
|
+
- **Next.js cache awareness**: `⚡ served by the Next.js cache — no network request was made`.
|
|
51
|
+
- **Hints for common mistakes**:
|
|
52
|
+
- JSON sent without `Content-Type: application/json`
|
|
53
|
+
- relative URLs on the server
|
|
54
|
+
- HTML returned instead of JSON
|
|
55
|
+
- lowercase `patch`
|
|
56
|
+
- redirects
|
|
57
|
+
- `ECONNREFUSED`, DNS, TLS and timeout errors
|
|
58
|
+
- **Dashboard** at `/fetch-inspector`:
|
|
59
|
+
- filters and keyboard navigation
|
|
60
|
+
- Pause / Resume
|
|
61
|
+
- Hide secrets (for screen sharing)
|
|
62
|
+
- dark mode
|
|
63
|
+
- **Export HAR**, sanitized or with secrets, which you can drop into Chrome DevTools
|
|
64
|
+
- **Development only.** It does nothing in production unless you opt in, and the dashboard is always 404 there.
|
|
65
|
+
- **Zero dependencies.** Works with Next.js 13.4 → 16, Turbopack and webpack, Node.js and Edge.
|
|
66
|
+
|
|
67
|
+
## Quick start
|
|
68
|
+
|
|
69
|
+
**1. Install**
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npm i -D next-fetch-inspector
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**2. Add `instrumentation.ts`** at the project root (or in `src/`):
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
// instrumentation.ts
|
|
79
|
+
export async function register() {
|
|
80
|
+
if (process.env.NODE_ENV === 'development') {
|
|
81
|
+
await import('next-fetch-inspector/register')
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Run `next dev`. Every server-side fetch is now printed in your terminal.
|
|
87
|
+
|
|
88
|
+
**3. (Optional) Add the dashboard**
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
// app/fetch-inspector/route.ts
|
|
92
|
+
export { GET, POST } from 'next-fetch-inspector/route'
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The terminal prints a private link when `next dev` starts:
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
▸ next-fetch-inspector dashboard: http://localhost:3000/fetch-inspector#token=28a4…
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Open that link and you're in. The token stays in that browser tab. → [Full getting-started guide](./docs/getting-started.md)
|
|
102
|
+
|
|
103
|
+
## Screenshots
|
|
104
|
+
|
|
105
|
+
**Terminal.** Every request with its source, warnings, bodies and cURL:
|
|
106
|
+
|
|
107
|
+

|
|
108
|
+
|
|
109
|
+
**Copy cURL.** The real request, ready for the backend developer:
|
|
110
|
+
|
|
111
|
+

|
|
112
|
+
|
|
113
|
+
**Errors with hints:**
|
|
114
|
+
|
|
115
|
+

|
|
116
|
+
|
|
117
|
+
<details>
|
|
118
|
+
<summary>More screenshots: response viewer, Hide secrets, Pause, dark mode, locked page</summary>
|
|
119
|
+
|
|
120
|
+

|
|
121
|
+

|
|
122
|
+

|
|
123
|
+

|
|
124
|
+

|
|
125
|
+
|
|
126
|
+
</details>
|
|
127
|
+
|
|
128
|
+
## How it compares
|
|
129
|
+
|
|
130
|
+
| | next-fetch-inspector | Next.js `logging.fetches` | `next dev --inspect` | next-fetch-har | next-axios-network |
|
|
131
|
+
| --- | :---: | :---: | :---: | :---: | :---: |
|
|
132
|
+
| Works with the App Router | ✅ | ✅ | ✅ | ❌ wraps `_app` (Pages Router) | — |
|
|
133
|
+
| Native `fetch` | ✅ | ✅ | ✅ | ✅ | ❌ axios only |
|
|
134
|
+
| Request / response headers & bodies | ✅ | ❌ | ❌ | ✅ | ✅ |
|
|
135
|
+
| Copy as cURL | ✅ | ❌ | ❌ | — | — |
|
|
136
|
+
| Shows file:line of the call | ✅ | ❌ | ❌ | — | — |
|
|
137
|
+
| Detects Next.js cache hits | ✅ | ✅ | ❌ | — | — |
|
|
138
|
+
| Hints for common mistakes | ✅ | ❌ | ❌ | — | — |
|
|
139
|
+
| HAR export | ✅ | ❌ | ❌ | ✅ | — |
|
|
140
|
+
| Setup | `instrumentation.ts` | `next.config` | CLI flag | wrap `_app` | webpack plugin + extra process |
|
|
141
|
+
|
|
142
|
+
"—" means not documented by that project. Check its README for the current state.
|
|
143
|
+
|
|
144
|
+
## Configuration
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
// instrumentation.ts
|
|
148
|
+
export async function register() {
|
|
149
|
+
if (process.env.NODE_ENV === 'development') {
|
|
150
|
+
const { install } = await import('next-fetch-inspector')
|
|
151
|
+
install({
|
|
152
|
+
log: 'summary', // 'full' (default) | 'summary' | 'curl' | false
|
|
153
|
+
maxEntries: 50, // requests kept in memory (default 50)
|
|
154
|
+
ignore: ['/health'], // added to the built-in Next.js ignores
|
|
155
|
+
redactBodyKeys: ['iban'], // extra secret field names (terminal & shared exports)
|
|
156
|
+
})
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Every option, the environment variables, and the TypeScript types: → [docs/configuration.md](./docs/configuration.md)
|
|
162
|
+
|
|
163
|
+
## Is it safe?
|
|
164
|
+
|
|
165
|
+
Yes. It was designed so that your data is shown to you, and only to you, only in development:
|
|
166
|
+
|
|
167
|
+
- **Development only.** `register` does nothing when `NODE_ENV=production`, and the dashboard route is 404 in production.
|
|
168
|
+
- **A private link.** The dashboard opens from a link with a random token, printed only in your terminal. The token stays in that browser tab, and no cookies are used. Other pages and scripts on `localhost`, other websites, and other devices on your network can't read the data.
|
|
169
|
+
- **Real values where you need them, masked where they travel.** The dashboard and "Copy cURL" show real values, like your browser's Network tab. The terminal, the default HAR export and "Copy redacted" mask tokens, cookies and passwords.
|
|
170
|
+
- **Safe to paste.** Copied cURL commands only replay the request, and terminal output can't be affected by captured data.
|
|
171
|
+
|
|
172
|
+
Every protection has an automated test. Details: [docs/security.md](./docs/security.md)
|
|
173
|
+
|
|
174
|
+
## FAQ
|
|
175
|
+
|
|
176
|
+
**Why don't I see my server-side fetch requests in Chrome DevTools?**
|
|
177
|
+
Server Components, Route Handlers and Server Actions run in Node.js on the server. The browser only receives the result. next-fetch-inspector records those requests on the server and shows them in your terminal and a local dashboard.
|
|
178
|
+
|
|
179
|
+
**How do I log the full request and response of `fetch` in Next.js?**
|
|
180
|
+
Install `next-fetch-inspector` as a dev dependency and import `next-fetch-inspector/register` from `instrumentation.ts` in development. Every server-side `fetch` is then printed with headers, bodies and a cURL command.
|
|
181
|
+
|
|
182
|
+
**How do I get a cURL command for a fetch made by my Next.js server?**
|
|
183
|
+
Open the dashboard, select the request, and click **Copy cURL**. It contains the exact URL, headers (including `Authorization`) and body that were sent.
|
|
184
|
+
|
|
185
|
+
**Is the response served from the Next.js cache or from the network?**
|
|
186
|
+
The inspector tells you. Cache hits are marked `⚡ served by the Next.js cache — no network request was made`.
|
|
187
|
+
|
|
188
|
+
**Does it work in production?**
|
|
189
|
+
It's made for `next dev`. If you need records from production, `allowInProduction: true` turns on terminal logging, `onEntry` and `getEntries()`. The dashboard stays a development-only page.
|
|
190
|
+
|
|
191
|
+
**Does it work with axios?**
|
|
192
|
+
It records `fetch`. axios works when you use its `fetch` adapter (`adapter: 'fetch'`).
|
|
193
|
+
|
|
194
|
+
**Does it slow my app down?**
|
|
195
|
+
Responses are cloned and read in the background, so your code never waits. Bodies are capped (`maxBodySize`), and only the last 50 requests are kept.
|
|
196
|
+
|
|
197
|
+
More: [docs/faq.md](./docs/faq.md)
|
|
198
|
+
|
|
199
|
+
## Documentation
|
|
200
|
+
|
|
201
|
+
| Guide | What's inside |
|
|
202
|
+
| --- | --- |
|
|
203
|
+
| [Getting started](./docs/getting-started.md) | Install, `instrumentation.ts`, dashboard, first request |
|
|
204
|
+
| [Configuration](./docs/configuration.md) | Every option, env vars, TypeScript types |
|
|
205
|
+
| [Dashboard](./docs/dashboard.md) | Tabs, Copy cURL vs Copy redacted, HAR, Pause, keyboard |
|
|
206
|
+
| [How it works](./docs/how-it-works.md) | Fetch wrapping, cache detection, source maps |
|
|
207
|
+
| [Testing](./docs/testing.md) | 42 automated tests, end-to-end checks, how to run them |
|
|
208
|
+
| [Security](./docs/security.md) | How your data is protected, and how each protection is tested |
|
|
209
|
+
| [FAQ](./docs/faq.md) | Common questions and troubleshooting |
|
|
210
|
+
| [Changelog](./CHANGELOG.md) | Release history |
|
|
211
|
+
| [العربية](./README.ar.md) | شرح بالعربي |
|
|
212
|
+
|
|
213
|
+
**Playground:** [AhmedNnasser11/next-fetch-inspector-playground](https://github.com/AhmedNnasser11/next-fetch-inspector-playground). A Next.js 16 app with a CRUD mock API and 21 success and error scenarios to try every feature.
|
|
214
|
+
|
|
215
|
+
## Requirements
|
|
216
|
+
|
|
217
|
+
- Next.js ≥ 13.4 (App Router + `instrumentation.ts`). Tested on **Next.js 16.4** with Turbopack and `--webpack`.
|
|
218
|
+
- Node.js ≥ 20.9. **≥ 20.16 recommended**, for source locations and a dashboard token that survives restarts.
|
|
219
|
+
|
|
220
|
+
## Credits
|
|
221
|
+
|
|
222
|
+
Built by [Ahmed Nasser](https://github.com/AhmedNnasser11) with **Claude Opus 5.5** (Anthropic): design, implementation, security review and tests.
|
|
223
|
+
|
|
224
|
+
Contributions welcome. Run `npm test` before opening a PR. MIT License.
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Security
|
|
2
|
+
|
|
3
|
+
next-fetch-inspector is a development tool. It shows your server-side requests exactly as sent, so the dashboard is private to you by design:
|
|
4
|
+
|
|
5
|
+
- **Development only.** The dashboard route is 404 in production.
|
|
6
|
+
- **Private link.** The dashboard opens from a link with a random token, printed only in your terminal. The token lives in that browser tab only. No cookies are used, so other scripts and pages on `localhost`, other websites, and other devices on your network can't read the data.
|
|
7
|
+
- **Masked where it travels.** The terminal, `onEntry`, "Copy redacted", the default HAR export and "Hide secrets" mask tokens, cookies and passwords.
|
|
8
|
+
- **Safe cURL.** Copied commands are quoted so that pasting them only replays the request.
|
|
9
|
+
- **Safe output.** Control characters from captured data are made visible, so they can't affect your terminal.
|
|
10
|
+
|
|
11
|
+
Full details, and how each protection is tested: [docs/security.md](./docs/security.md).
|
|
12
|
+
|
|
13
|
+
## Reporting a vulnerability
|
|
14
|
+
|
|
15
|
+
Please use GitHub's **private vulnerability reporting** on this repository (Security → Report a vulnerability) rather than a public issue. You'll get a reply as soon as possible.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Configuration
|
|
2
|
+
|
|
3
|
+
You can use next-fetch-inspector in two ways:
|
|
4
|
+
|
|
5
|
+
- **Zero config:** `await import('next-fetch-inspector/register')`.
|
|
6
|
+
- **With options:** call `install()` yourself.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
// instrumentation.ts
|
|
10
|
+
export async function register() {
|
|
11
|
+
if (process.env.NODE_ENV === 'development') {
|
|
12
|
+
const { install } = await import('next-fetch-inspector')
|
|
13
|
+
install({ log: 'summary', maxEntries: 100 })
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`install()` is safe to call more than once. Later calls update the options.
|
|
19
|
+
|
|
20
|
+
## Options
|
|
21
|
+
|
|
22
|
+
| Option | Type | Default | What it does |
|
|
23
|
+
| --- | --- | --- | --- |
|
|
24
|
+
| `log` | `'full' \| 'summary' \| 'curl' \| false` | `'full'` (`'summary'` when `CI` is set) | Terminal output. `summary` shows one block per request (status, time, source, warnings). `curl` adds the cURL. `full` adds headers and bodies. |
|
|
25
|
+
| `maxEntries` | `number` | `50` | How many requests are kept in memory for the dashboard. Oldest are dropped first. |
|
|
26
|
+
| `maxBodySize` | `number` | `100_000` | Max characters of each request / response body that are captured. Larger bodies are cut, with a warning and a `# ⚠` note in the cURL. |
|
|
27
|
+
| `maxLogBodySize` | `number` | `1_500` | Max characters of a body printed in the terminal. The dashboard shows up to `maxBodySize`. |
|
|
28
|
+
| `bodyTimeoutMs` | `number` | `5_000` | Stop reading a streaming body after this long, so its entry still completes. |
|
|
29
|
+
| `redact` | `boolean` | `true` | Mask secrets in the **terminal** and `onEntry`. The dashboard always shows real values. The sanitized HAR and "Hide secrets" always mask. |
|
|
30
|
+
| `redactHeaders` | `(string \| RegExp)[] \| false` | built-in | Extra header names to mask, **added** to the built-in patterns. `false` turns header masking off. |
|
|
31
|
+
| `redactQueryParams` | `(string \| RegExp)[] \| false` | built-in | Extra query / fragment parameter names to mask. |
|
|
32
|
+
| `redactBodyKeys` | `(string \| RegExp)[] \| false` | built-in | Extra JSON / form field names to mask in bodies. |
|
|
33
|
+
| `ignore` | `(string \| RegExp)[]` | `[]` | URLs to skip (substring or RegExp). **Added** to the built-in Next.js ignores (telemetry, `_rsc`, `/_next/static` …). |
|
|
34
|
+
| `dashboardToken` | `boolean` | `true` | Require the private link's token to read dashboard data. `false` is meant for isolated environments; only `localhost` host names are answered. |
|
|
35
|
+
| `dashboardHosts` | `string[]` | `[]` | With `dashboardToken: false`, extra `Host` names to answer (e.g. `'dev.box:3000'`). |
|
|
36
|
+
| `dashboardPath` | `string \| false` | `'/fetch-inspector'` | Path used in the startup link. `false` prints no link. |
|
|
37
|
+
| `allowInProduction` | `boolean` | `false` | Also record when `NODE_ENV=production` (terminal, `onEntry`, `getEntries()`). The dashboard is a development-only page. |
|
|
38
|
+
| `onEntry` | `(entry: FetchEntry) => void` | – | Called for every finished request, with the same masking as the terminal. |
|
|
39
|
+
|
|
40
|
+
### Built-in secret patterns
|
|
41
|
+
|
|
42
|
+
These are masked in the terminal, `onEntry`, "Copy redacted", the sanitized HAR and "Hide secrets":
|
|
43
|
+
|
|
44
|
+
- **Headers:**
|
|
45
|
+
- `authorization`, `proxy-authorization`
|
|
46
|
+
- anything containing `cookie`, `token`, `secret`, `password`, `api-key`, `signature`, `credential`, `session`, `csrf`, `xsrf`
|
|
47
|
+
- `x-*-key`
|
|
48
|
+
- **Query and fragment params:**
|
|
49
|
+
- anything containing `token`, `secret`, `password`, `api_key`, `signature`, `credential`, `session`
|
|
50
|
+
- exactly `key`, `code`, `auth`, `access_key`
|
|
51
|
+
- **Body fields** (JSON, urlencoded, multipart, `a=1&b=2` text):
|
|
52
|
+
- anything containing `token`, `secret`, `password`, `api_key`, `credential`, `private_key`, `signature`
|
|
53
|
+
- exactly `authorization`, `cookie`, `session`, `otp`, `pin`, `cvv`, `cvc`, `card_number`, `ssn`
|
|
54
|
+
- **URLs:** `user:password@` credentials, and `Location` / `Referer` / `Link` headers.
|
|
55
|
+
|
|
56
|
+
The built-in patterns are exported as `DEFAULT_REDACT_HEADERS`, `DEFAULT_REDACT_QUERY` and `DEFAULT_REDACT_BODY_KEYS`.
|
|
57
|
+
|
|
58
|
+
> RegExps with the `g` or `y` flag are made stateless automatically, so they match every time.
|
|
59
|
+
|
|
60
|
+
## Environment variables
|
|
61
|
+
|
|
62
|
+
| Variable | Effect |
|
|
63
|
+
| --- | --- |
|
|
64
|
+
| `NEXT_FETCH_INSPECTOR=off` | Disable completely without touching code. |
|
|
65
|
+
| `NEXT_FETCH_INSPECTOR_LOG=summary` | `full`, `summary`, `curl` or `off`. Unknown values print a warning. |
|
|
66
|
+
| `NEXT_FETCH_INSPECTOR_TOKEN=…` | Use a fixed dashboard token instead of a generated one: at least 32 characters, letters and digits. Shorter values are ignored. |
|
|
67
|
+
|
|
68
|
+
## Programmatic API
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import {
|
|
72
|
+
install, uninstall, // patch / unpatch fetch
|
|
73
|
+
getEntries, viewEntry, // read captured requests
|
|
74
|
+
clearEntries, setPaused, isPaused, isInstalled, getVersion,
|
|
75
|
+
getDashboardToken,
|
|
76
|
+
toCurl, toFetchSnippet, toHar, // formatters
|
|
77
|
+
DEFAULT_IGNORE, DEFAULT_REDACT_HEADERS, DEFAULT_REDACT_QUERY, DEFAULT_REDACT_BODY_KEYS, REDACTED,
|
|
78
|
+
} from 'next-fetch-inspector'
|
|
79
|
+
|
|
80
|
+
getEntries() // real values, like the dashboard
|
|
81
|
+
getEntries({ redacted: true }) // secrets masked
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### `FetchEntry`
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
interface FetchEntry {
|
|
88
|
+
id: number
|
|
89
|
+
startedAt: number; finishedAt?: number; duration?: number // ms, until response headers
|
|
90
|
+
runtime: string // 'nodejs' | 'edge'
|
|
91
|
+
source?: string // 'app/page.tsx:9:23'
|
|
92
|
+
servedFrom?: 'network' | 'next-cache'
|
|
93
|
+
nextOptions?: { cache?: string; revalidate?: number | false; tags?: string[] }
|
|
94
|
+
request: { method: string; url: string; headers: Record<string, string>; body: CapturedBody | null }
|
|
95
|
+
response?: { status: number; statusText: string; ok: boolean; redirected: boolean; url?: string;
|
|
96
|
+
headers: Record<string, string>; body: CapturedBody | null }
|
|
97
|
+
error?: { name: string; message: string; cause?: string }
|
|
98
|
+
warnings: string[]
|
|
99
|
+
curl: string // exactly as sent (or masked, in a redacted view)
|
|
100
|
+
curlRedacted: string // always masked
|
|
101
|
+
fetchSnippet: string
|
|
102
|
+
redacted?: boolean
|
|
103
|
+
done: boolean
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Example: send entries to a file
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import fs from 'node:fs'
|
|
111
|
+
install({
|
|
112
|
+
log: 'summary',
|
|
113
|
+
onEntry: (e) => fs.appendFileSync('.next/fetch-log.ndjson', JSON.stringify(e) + '\n'),
|
|
114
|
+
})
|
|
115
|
+
```
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# The dashboard
|
|
2
|
+
|
|
3
|
+
`/fetch-inspector` is a Network tab for your Next.js **server**. It lists the last 50 server-side `fetch()` calls. The list refreshes once a second, and only when something changed.
|
|
4
|
+
|
|
5
|
+
Open it with the `#token=…` link printed in your terminal. The token stays in that tab, so a new tab needs the link again.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## The list
|
|
10
|
+
|
|
11
|
+
| Column | Meaning |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| **#** | Request number since the dev server started |
|
|
14
|
+
| **Method** | Exactly as sent. A lowercase `patch` stays lowercase, with a warning. |
|
|
15
|
+
| **Status** | Colored by class (2xx green, 3xx teal, 4xx orange, 5xx red). `failed` means no response: DNS, connection refused, timeout, or an invalid URL. |
|
|
16
|
+
| **URL** | Host + path + query. A `⚠ n` badge means there are hints. |
|
|
17
|
+
| **From** | The file and line in your code that called `fetch` |
|
|
18
|
+
| **Time** | Time until the response headers arrived, or `⚡ cache` when Next.js answered from its cache |
|
|
19
|
+
|
|
20
|
+
**Filter:** type anything, e.g. `POST 500 api.github.com page.tsx`. Every word must match. The dropdown filters by status class or errors only.
|
|
21
|
+
|
|
22
|
+
**Keyboard:** `/` focuses the filter, `↑`/`↓` or `j`/`k` move through the list.
|
|
23
|
+
|
|
24
|
+
## Detail tabs
|
|
25
|
+
|
|
26
|
+
| Tab | Shows |
|
|
27
|
+
| --- | --- |
|
|
28
|
+
| **Overview** | Hints, URL, status, duration, called from, runtime, Next.js cache options, served from, and the cURL |
|
|
29
|
+
| **Request** | Request headers and body (JSON pretty-printed, form fields listed) |
|
|
30
|
+
| **Response** | Response headers and body |
|
|
31
|
+
| **cURL** | The command, with **Copy cURL** and **Copy redacted** |
|
|
32
|
+
| **fetch()** | The same request as a `fetch()` call |
|
|
33
|
+
|
|
34
|
+

|
|
35
|
+
|
|
36
|
+
## Copy cURL vs Copy redacted
|
|
37
|
+
|
|
38
|
+

|
|
39
|
+
|
|
40
|
+
- **Copy cURL** is the request **exactly as sent**: the real `Authorization`, cookies, API keys and body. Send it to your backend developer and they can reproduce the bug in one paste.
|
|
41
|
+
- **Copy redacted** is the same command with secrets replaced by `[REDACTED]`. Use it for GitHub issues, public channels and documentation.
|
|
42
|
+
|
|
43
|
+
If a body was bigger than `maxBodySize`, the cURL starts with a `# ⚠ … the body was cut` comment line. That way nobody replays half a body without knowing it.
|
|
44
|
+
|
|
45
|
+
## Hide secrets
|
|
46
|
+
|
|
47
|
+
Screen sharing? Click **Hide secrets** to mask tokens, cookies and passwords everywhere on screen. The choice is remembered in this browser.
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
51
|
+
## Pause / Resume
|
|
52
|
+
|
|
53
|
+
**Pause** stops *recording*. Your app keeps making requests normally; they just aren't captured. A yellow bar shows while paused, and the terminal prints `⏸ recording paused` / `▶ recording resumed`. The pause lasts until you resume or restart `next dev`.
|
|
54
|
+
|
|
55
|
+

|
|
56
|
+
|
|
57
|
+
**Clear** empties the list.
|
|
58
|
+
|
|
59
|
+
## Export HAR
|
|
60
|
+
|
|
61
|
+
Two buttons, like Chrome DevTools:
|
|
62
|
+
|
|
63
|
+
- **Export HAR**: secrets masked. Safe to attach to an issue.
|
|
64
|
+
- **Export HAR (with secrets)**: real values, for your own use.
|
|
65
|
+
|
|
66
|
+
Drag a `.har` file into Chrome DevTools → Network to inspect it there, or open it in any HAR viewer.
|
|
67
|
+
|
|
68
|
+
## Dark mode
|
|
69
|
+
|
|
70
|
+
The dashboard follows your system theme.
|
|
71
|
+
|
|
72
|
+

|
package/docs/faq.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# FAQ: debugging server-side fetch in Next.js
|
|
2
|
+
|
|
3
|
+
### Why don't server-side fetch requests show up in Chrome DevTools' Network tab?
|
|
4
|
+
Server Components, Route Handlers, Server Actions and `generateMetadata` run in Node.js on the server. Their `fetch()` calls never pass through the browser, so DevTools can't see them. next-fetch-inspector records them on the server and shows them in the terminal and in a local dashboard.
|
|
5
|
+
|
|
6
|
+
### How do I see the request headers and body that Next.js sent to my API?
|
|
7
|
+
Add `await import('next-fetch-inspector/register')` to `instrumentation.ts` in development. Each request is printed with its headers and body. The dashboard's **Request** tab shows them unmasked.
|
|
8
|
+
|
|
9
|
+
### How do I copy a server-side Next.js fetch as cURL?
|
|
10
|
+
Open `/fetch-inspector` with the link printed in your terminal, select the request, and click **Copy cURL** (exact) or **Copy redacted** (secrets masked).
|
|
11
|
+
|
|
12
|
+
### Why does my API say "Unsupported Media Type" or get an empty body?
|
|
13
|
+
You probably sent `body: JSON.stringify(data)` without `headers: { 'Content-Type': 'application/json' }`. fetch then sends `text/plain`. The inspector warns about this on every such request.
|
|
14
|
+
|
|
15
|
+
### Why does `fetch('/api/users')` fail on the server?
|
|
16
|
+
The server has no base URL, so relative URLs fail with `Failed to parse URL`. Use an absolute URL (for example `${process.env.API_URL}/users`), or call your logic directly instead of your own Route Handler.
|
|
17
|
+
|
|
18
|
+
### My PATCH request returns 405. Why?
|
|
19
|
+
`fetch(url, { method: 'patch' })` sends the method **lowercase**. fetch only upper-cases GET, POST, PUT, DELETE, HEAD and OPTIONS. Use `'PATCH'`. The inspector shows the method exactly as sent, with a warning.
|
|
20
|
+
|
|
21
|
+
### Was my response served from the Next.js cache?
|
|
22
|
+
The inspector marks it as `⚡ served by the Next.js cache — no network request was made` (`servedFrom: 'next-cache'`).
|
|
23
|
+
|
|
24
|
+
### Is it safe to install?
|
|
25
|
+
Yes. It runs in development, and the dashboard is 404 in production. The dashboard opens only from a private link printed in your terminal; that link works in one browser tab and uses no cookies. Secrets are masked in the terminal and in shared exports. See [security.md](./security.md).
|
|
26
|
+
|
|
27
|
+
### Does it store my requests?
|
|
28
|
+
Only in memory, the last 50 by default (`maxEntries`), until you click **Clear** or restart `next dev`. Nothing is written to disk except the dashboard token and HAR files you export.
|
|
29
|
+
|
|
30
|
+
### Does it work with axios, ky, ofetch, GraphQL clients?
|
|
31
|
+
Anything built on `fetch` works: ky, ofetch, graphql-request, Apollo with fetch, and axios with `adapter: 'fetch'`. axios' default Node adapter (`http`) is not captured.
|
|
32
|
+
|
|
33
|
+
### Does it work with the Pages Router?
|
|
34
|
+
It should: `instrumentation.ts` wraps `fetch` for the whole server process, so `getServerSideProps` and API routes go through it too. Testing so far has been on the App Router, so please open an issue if something is missing. Next.js ≥ 13.4 is required.
|
|
35
|
+
|
|
36
|
+
### Does it work with Turbopack / webpack / Edge?
|
|
37
|
+
Turbopack and webpack: yes. Turbopack gives exact `file:line:col`; webpack gives the file. Edge: requests are logged to the terminal, but keep the dashboard route on Node.js.
|
|
38
|
+
|
|
39
|
+
### How do I turn it off temporarily?
|
|
40
|
+
Set `NEXT_FETCH_INSPECTOR=off`, or click **Pause** in the dashboard.
|
|
41
|
+
|
|
42
|
+
### Where can I try it?
|
|
43
|
+
In the [playground](https://github.com/AhmedNnasser11/next-fetch-inspector-playground). It has 21 ready-made success and error scenarios.
|