Giter Club home page Giter Club logo

next-status-proxy-fork's Introduction

NextStatusProxy

Overview

NextStatusProxy is a middleware designed for Next.js applications that need custom status code handling. As of Next.js 13, setting custom status codes directly in responses is not supported. This middleware provides a solution by allowing developers to set custom status codes via meta tags in their Next.js applications. The middleware intercepts these responses, extracts the custom status code from the meta tag, and sets it in the response to the client.

Features

  • Custom Status Code Handling: Allows setting custom status codes via meta tags.
  • Path Ignoring Capability: Exclude specific paths from processing using a .proxystatusignore file.
  • Seamless Integration with Next.js: Designed to work specifically with Next.js applications.
  • Streaming Support: Preserves the streaming functionality of Next.js responses.
  • Developer and SEO Friendly: Enhances development flexibility and SEO capabilities.

Installation

To get started, clone this repository and install the required dependencies.

git clone https://the-repository-url.git
cd next-status-proxy
npm install

Configuration

Middleware Setup

Create a .env file in the root of your project and configure it as per .env.example:

TARGET_URL=http://localhost:3000
TARGET_META_NAME=app:status
PROXY_PORT=3001

Path Ignoring Feature

Create a .proxystatusignore file in the project root and list patterns for paths you want to ignore. Each pattern should be on a new line. The middleware will not process responses for these paths. Ideally, all paths in your Next.js project, except the page paths in your app folder, should be included here.

Example .proxystatusignore content:

/api/*
/_next*
/sitemap/*
/favicon.ico
/robots.txt
/*.svg
/*.png
/*.html

Next.js Project Setup

In your Next.js project, configure the metadata in your pages as follows.

export const metadata: Metadata = {
  other: {
    'app:status': 410 // Example status code
  }
};

These values are the default values.

Usage

To start the proxy server, run:

npm run build
npm start

This runs the proxy middleware on the PROXY_PORT, directing requests to the TARGET_URL.

How It Works

The middleware checks for a specific meta tag (app:status) in the Next.js server responses. If found, the middleware uses its value to set the status code in the client response. Additionally, it respects path ignore patterns defined in .proxystatusignore.

next-status-proxy-fork's People

Contributors

sgezsat avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.