2.3.0 • Published 4 years ago

nextjs-koa-middleware v2.3.0

Weekly downloads
19
License
MIT
Repository
github
Last release
4 years ago

nextjs-koa-middleware

NextJS koa middleware

Codacy Badge CircleCI npm npm LICENSE Dependabot Status

System Requirements

Installation

# npm
npm i nextjs-koa-middleware
# yarn
yarn add nextjs-koa-middleware

Peer Dependency

Usage

  • 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('/PagePath', render('pageComponentName'));
nextRouter.all('*', handleRoutes());

export default nextRouter;
  • Start koa server:
import koa from 'koa';
import nextRouter from './NextRouter';

const app = new Koa();
const port = process.env.PORT ?? 3000;
const host = process.env.HOST ?? 'localhost';

app.use(nextRouter.routes()).use(nextRouter.allowedMethods());
app.listen(port);

console.info(`listening on ${host}:${port}`);

License

Copylefted (c) 2020 Henrique Carvalho da Cruz Licensed under the MIT license.

2.3.0

4 years ago

2.2.0

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago