Skip to content

Latest commit

 

History

History
87 lines (67 loc) · 2.58 KB

README.md

File metadata and controls

87 lines (67 loc) · 2.58 KB

@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

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:

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;
}