Socket
Book a DemoInstallSign in
Socket

@foomo/next-proxy-middleware

Package Overview
Dependencies
Maintainers
4
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@foomo/next-proxy-middleware

1.0.8
latest
npmnpm
Version published
Weekly downloads
53
17.78%
Maintainers
4
Weekly downloads
 
Created
Source

npm npm Build Status

@foomo/next-proxy-middleware

A Next.js middleware for proxying requests to external services with advanced configuration options.

Installation

npm install @foomo/next-proxy-middleware

Usage

Import the middleware and configuration type in your Next.js middleware file:

import {
  createProxyMiddleware,
  DevProxyConfig,
} from "@foomo/next-proxy-middleware";

Configuration

The DevProxyConfig type defines the following options:

export type DevProxyConfig = {
  debug?: boolean; // Enable debug logging
  disable?: boolean; // Disable the proxy entirely
  remoteUrl: string | ((request: NextRequest) => string); // Remote URL or function to generate it
  allowResponseCompression?: boolean; // Allow response compression (default: false)
  overrideHostHeader?: boolean; // Override host header (default: true)
  overrideCookieDomain?: false | string; // Domain to use for cookies or false to disable
  basicAuth?: {
    authHeader: string; // Authorization header value
  };
  cfTokenAuth?: {
    clientId: string;
    clientSecret: string;
  };
};

Example

Here's an example of how to use the middleware in your middleware.ts file:

import {
  createProxyMiddleware,
  DevProxyConfig,
} from "@foomo/next-proxy-middleware";

const proxyConfig: DevProxyConfig = {
  remoteUrl: "https://api.example.com",
  basicAuth: {
    authHeader: "Basic abc123==",
  },
  overrideCookieDomain: "example.com",
};

export function middleware(request: NextRequest) {
  if (request.nextUrl.pathname.match("^/(api|webhooks)/")) {
    return proxyMiddleware(request);
  }
  return request;
}

export const config = {
  matcher: ["/api/:path*"],
};

const proxyMiddleware = createProxyMiddleware(proxyConfig);

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.

License

Distributed under MIT License, please see license file within the code for more details.

Made with ♥ foomo by bestbytes

Keywords

foomo

FAQs

Package last updated on 21 Jul 2025

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.