nx-nginx-routes

1.2.0 • Public • Published

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.

Package Sidebar

Install

npm i nx-nginx-routes

Weekly Downloads

10

Version

1.2.0

License

MIT

Unpacked Size

88.7 kB

Total Files

20

Last publish

Collaborators

  • j-badr