revskill10 / next-nginx-routes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

next-nginx-routes

Generate Nginx routes configuration file for Next.js static HMTL export.

This NPM package allows you to convert Next.js routes like:

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

... into Nginx routes like:

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

Getting started

Installation

yarn add --dev next-nginx-routes

Generate Nginx configuration file

Add next-nginx-routes to your export script:

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

And run Next.js export:

yarn run export

Include Nginx configuration file

Finally include the generated configuration file next-routes.conf and the Next.js output in your Nginx site configuration file.

Requirements

More

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

About


Languages

Language:JavaScript 93.6%Language:Dockerfile 6.4%