# NextJS（fetch）

> 使用 Proxyman 自动设置中预配置的终端，抓包 Next.js 服务端 fetch() 和 Server Components 的 HTTPS 请求。

## 1. 问题 {#1-problem}

* Proxyman 无法抓取 NextJS 中 `use server` 代码的任何流量
* 这是因为 NextJS 中的 `fetch` 不遵循系统 HTTP 代理设置，因此没有流量会经过 Proxyman 应用。

## 2. 解决方案 {#2-solution}

1. 启动预配置的终端：Setup 菜单 -> Automatic Setup -> 点击 “Open New Terminal”
2. 会打开一个新的终端 -> 在此终端中启动你的 NextJS 服务器。例如：`npm run dev`
3. 在 `fetch` 上使用 `no-cache`

```js
export default async function MyPage() {
  const res = await fetch('https://httpbin.org/anything', { cache: 'no-cache' }) // no cache, or no request is sent to Proxyman
  return <div>My Page{res.text()}</div>
}
```

4. 重新加载你的网站
5. 完成 ✅ Proxyman 应用会抓取你的 HTTP 流量

![Proxyman 预配置终端中运行的 Next.js 开发服务器，以及 Proxyman 中抓取到的服务端 fetch 请求](https://proxyman.com/docs/assets/335782543-6e0c4eeb-435d-4589-b2dd-4087f3827f3a.jpg)

_在 Proxyman 中抓取 NextJS 的 fetch 请求_

## 3. 参考资料 {#3-reference}

* [https://github.com/ProxymanApp/Proxyman/issues/2038](https://github.com/ProxymanApp/Proxyman/issues/2038)

## 了解更多 {#learn-more}

* [在 NextJS 服务端抓取 HTTP 请求](https://proxyman.com/posts/2024-06-10-Capture-HTTPS-From-NextJS-Server-Components)
