NextJS koa middleware
- NodeJS (version >= 12).
# npm
npm i nextjs-koa-middleware
# yarn
yarn add nextjs-koa-middleware
- koa-router (version <= 8.0.8)
- Define environment variables:
NODE_ENV=development
# Relative path to .next directory
NEXT_CLIENT_DIR=/
NEXT_CONFIG_PATH=/next.config.js
- Define NextJS Routes:
import Router from 'koa-router'
import { handle, render, defaultReturn } from 'nextjs-koa-middleware'
const nextRouter = new Router()
nextRouter.use(defaultReturn())
nextRouter.get('/custom-path', render('pageComponentName'))
nextRouter.all('*', handleRoutes())
export default nextRouter
Copylefted (c) 2020 Henrique Carvalho da Cruz Licensed under the MIT license.