@progfay/nextjs-ssg-rewrite-rule-gen
v1.1.0
Published
generate nginx rewrite rules for Next.js SSG (Pages Router)
Downloads
10,794
Readme
@progfay/nextjs-ssg-rewrite-rule-gen
Description
Next.js supports Static Exports.
However, it's a lot of work to manage the routing for the generated file without Vercel. Dynamic Routes feature makes routing more difficult.
This application automatically generates nginx rewrite rules for generated files.
Requirements
- Next.js (Pages Router only)
- nginx
Installation
npm install -D @progfay/nextjs-ssg-rewrite-rule-gen
Configuration
[!NOTE] This application is available with zero configuration.
You can run this application with config in following command: nextjs-ssg-rewrite-rule-gen --config config.json
{
"pagesDirPath": "apps/src/pages",
"ignoreRoutes": ["/debug"],
"nginxConfigs": [
{
"pattern": "^/credential$",
"directives": ["add_header Cache-Control \"no-store\";"]
}
],
"basePath": "/app",
"trailingSlash": true
}
Available configs:
pagesDirPath
: customize path forpages
directoryignoreRoutes
: exclude specific paths from outputsnginxConfigs
: customize configuration inside of nginxlocation
directivepattern
: pattern string ofRegExp
directives
: additional nginx directives
basePath
: next.config.js Options: basePath | Next.jstrailingSlash
: next.config.js Options: trailingSlash | Next.js
How to work
pages
directory:
pages
└── user
├── [id]
└── index.js
└── new
└── index.js
↓
Generated files with Static Exports (next build
and output: "export"
):
out
└── user
├── [id].html
└── new.html
↓
nginx rewrite rules (generated by @progfay/nextjs-ssg-rewrite-rule-gen
):
location ~ ^/user/new/?$ {
rewrite ^/user/new/?$ /user/new.html break;
}
location ~ ^/user/[^/]+?/?$ {
rewrite ^/user/[^/]+?/?$ /user/[id].html break;
}