npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

next-http-inspector

v0.2.11

Published

Next Http Inspector - Interceptors for Next.js with WebSocket logging and monitoring (dev-only).

Readme

Next Http Inspector

Fetch interceptor for Next.js that connects directly to external WebSocket servers (dev-only).

This package provides a fetch interceptor that captures HTTP requests and responses, connecting directly to external WebSocket servers for real-time monitoring.

🎯 Focus

This package connects directly to external WebSocket servers using only the ws library. It does not require any external packages and creates its own WebSocket client connections.

✨ Features

  • 🔍 Fetch Interceptor: Captures all HTTP requests and responses
  • 📡 Direct WebSocket Connection: Connects directly to external servers
  • 🛡️ Development Only: Automatically disabled in production
  • 🚀 Zero External Dependencies: Only requires ws library
  • 🔒 Single Initialization: Prevents multiple initializations automatically

🚀 Installation

⚠️ Development Only: This package is designed exclusively for development environments. Do not install in production.

npm install --save-dev next-http-inspector

📖 Usage

For Next.js

  1. Initialize in your root layout (server-side only):
// app/layout.tsx (or pages/_app.tsx for Pages Router)
import { initFetchServerInterceptor } from 'next-http-inspector';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  // Initialize only on server side
  if (typeof window === 'undefined') {
    initFetchServerInterceptor({
      websocket: { enabled: true, port: 8080 },
      http: { enabled: true, host: 'localhost', port: 3001, endpoint: '/api/logs' }
    });
  }

  return (
    <html>
      <body>{children}</body>
    </html>
  );
}
  1. Start external servers (in a separate terminal):
# Install the server globally (one-time setup)
npm install -g next-http-inspector-server

# Start the server
next-inspector-server --ui-port 3001 --ws-port 8080
  1. Start your Next.js app:
npm run dev
  1. Access the monitoring UI:

Open http://localhost:3001/ui in your browser.

Configuration Options

initFetchServerInterceptor({
  websocket: {
    enabled: true,          // Enable WebSocket connection
    port: 8080             // WebSocket port
  },
  http: {
    enabled: true,         // Enable HTTP fallback
    host: 'localhost',     // HTTP server host
    port: 3001,            // HTTP server port
    endpoint: '/api/logs'  // HTTP endpoint
  },
  fetch: global.fetch  // Optional: custom fetch function
});

🏗️ Architecture

┌─────────────────────────────────────┐
│           Next.js App               │
│  ┌─────────────────────────────────┐│
│  │     Interceptors Package        ││
│  │  ┌─────────────────────────────┐││
│  │  │  Fetch Interceptor          │││
│  │  └─────────────────────────────┘││
│  └─────────────────────────────────┘│
└─────────────────────────────────────┘
                    │
                    │ Direct WebSocket Client
                    ▼
┌─────────────────────────────────────┐
│    External Server Package          │
│  ┌─────────────────────────────────┐│
│  │  WebSocket Server (port 8080)   ││
│  │  UI Server (port 3001)          ││
│  └─────────────────────────────────┘│
└─────────────────────────────────────┘

Key Points:

  • This package creates its own WebSocket client connections
  • No external package dependencies required
  • Direct connection to external WebSocket servers
  • Ultra-clean separation of concerns
  • Single initialization prevents duplicate setup

🔧 Development

Build

npm run build

Development Mode

npm run dev

📦 Package Structure

src/
├── index.ts                    # Main initFetchServerInterceptor function
├── types.ts                    # TypeScript definitions
└── interceptors/
    └── fetchInterceptor.ts      # HTTP request/response interceptor

🔗 Related Packages

🛠️ Troubleshooting

No Data Appearing in UI

  1. Check external servers are running:

    next-inspector-server --ui-port 3001 --ws-port 8080
  2. Verify ports match:

    • WebSocket port in initFetchServerInterceptor() should match --ws-port
    • UI port should match --ui-port
  3. Check logs:

    • Look for "🚀 Initializing Fetch Server Interceptor..." in console
    • Verify interceptor is enabled: "✅ Fetch Server Interceptor initialized successfully!"

Initialization Issues

The package automatically prevents multiple initializations. If you need to reinitialize:

  1. Restart your Next.js app:

    # Stop app (Ctrl+C)
    npm run dev
  2. Ensure initialization happens only on server side:

    if (typeof window === 'undefined') {
     initFetchServerInterceptor({ ... });

}


### Connection Issues

If WebSocket connection fails:

1. **Check server is running**:
```bash
curl http://localhost:3001/ui
  1. Verify port availability:

    lsof -i :8080
  2. Check connection logs:

    • Look for WebSocket connection messages in console
    • HTTP fallback will be used automatically if WebSocket fails

📄 License

MIT

🤝 Contributing

Contributions are welcome! Please read our contributing guidelines and submit pull requests to our repository.

📞 Support

If you encounter any issues or have questions, please open an issue on our GitHub repository.