
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
next-axios-network
Advanced tools
一款在开发时监控 next.js + axios 项目服务端请求的 Network 面板
在使用 next.js 开发时,有时候会遇到服务端请求无法详细 debug 的烦恼,例如:
// `pages` directory
export const getStaticProps = async () => {
const data = await axios.get("https://example.com/api/home");
return {
props: {
data,
},
};
};
// `app` directory
export default async function Dashboard() {
const data = await axios.get("https://example.com/api/home");
return (
<ul>
{data.map((item) => (
<li key={item.id}>{item.name}</li>
))}
</ul>
);
}
这样的请求是在 node 环境进行的,无法通过浏览器 Network 面板进行监控,有了 next-axios-network 即可解决这个痛点
npm i next-axios-network -D
next.config.js
加入配置:const NextAxiosNetworkPlugin = require("next-axios-network/plugin");
/** @type {import('next').NextConfig} */
const nextConfig = {
webpack: (config) => {
config.plugins.push(NextAxiosNetworkPlugin());
return config;
},
// ...
};
module.exports = nextConfig;
import axios from "axios";
import nextAxiosNetwork from "next-axios-network";
nextAxiosNetwork(axios);
如果使用了自定义 axios 实例,需要手动引入拦截器,例如:
import axios from "axios";
import nextAxiosNetwork, { middlewares } from "next-axios-network";
nextAxiosNetwork(axios);
const yourAxiosInstance = axios.create({
/** ... */
});
yourAxiosInstance.instance.interceptors.request.use(
middlewares.requestMiddleWare,
middlewares.requestError
);
yourAxiosInstance.instance.interceptors.response.use(
middlewares.responseMiddleWare,
middlewares.responseError
);
完成上述配置,启动项目后访问:
http://localhost:2999
即可看到监控面板
在上述 NextAxiosNetworkPlugin 中可配置自定义参数,例如:
const NextAxiosNetworkPlugin = require("next-axios-network/plugin");
/** @type {import('next').NextConfig} */
const nextConfig = {
webpack: (config) => {
config.plugins.push(
NextAxiosNetworkPlugin({
maxCaches: 100, // 最大缓存请求日志数量,默认 50
})
);
return config;
},
// ...
};
module.exports = nextConfig;
如果有多个项目想共享面板,可以不配置打包插件,只配置拦截器并使用 npm 启动面板,例如:
import axios from "axios";
import nextAxiosNetwork from "next-axios-network";
nextAxiosNetwork(axios);
package.json
加入启动命令"scripts": {
"network-start": "nan-start",
},
npm run network-start
即可,多个项目同时启动,面板启动命令只需要在任意一个项目配置启动即可自定义参数可以通过启动命令设置环境变量,面板服务会读取 process.env.MAX_CACHES
FAQs
一款在开发时监控 next.js + axios 项目服务端请求的 Network 面板
We found that next-axios-network demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.