next-nginx-routes

1.2.1 • Public • Published

next-nginx-routes

Generate Nginx routes configuration file for Next.js static HMTL export, also known as output: export.

This dependency-free NPM package provides a NPM script to convert all your Next.js routes like:

{
  "page": "/[foo]",
  "regex": "^/([^/]+?)(?:/)?$",
  "routeKeys": { "foo": "foo" },
  "namedRegex": "^/(?<foo>[^/]+?)(?:/)?$"
}

... into Nginx routes like:

location ~ ^/([^/]+?)(?:/)?$ {
  try_files /[foo].html /index.html;
}

Note: currently only Next.js pages router is fully supported.

Getting started

Installation

yarn add --dev next-nginx-routes

Generate Nginx configuration file

Add next-nginx-routes to your build script:

{
  "build": "next build && next-nginx-routes"
}

And run Next.js export:

yarn run build

Include Nginx configuration file

Finally include the generated configuration file next-routes.conf in your Nginx site configuration file and make the Next.js out directory available to Nginx.

Requirements

More

  • See example folder for a minimal Docker example.
  • Read more about this approach in our blog post.

Dependencies (0)

    Dev Dependencies (6)

    Package Sidebar

    Install

    npm i next-nginx-routes

    Weekly Downloads

    1,777

    Version

    1.2.1

    License

    BSD-2-Clause

    Unpacked Size

    20.5 kB

    Total Files

    21

    Last publish

    Collaborators

    • friedjoff