1.12.0 • Published 4 months ago

koa-router-with-directory v1.12.0

Weekly downloads
16
License
MIT
Repository
github
Last release
4 months ago

koa-router-with-directory

attachDirToRouter() attaches your directory into koa-router.
The installations of koa and koa-router on your own are pre-requisites of this package.
See koa-router-with-directory.netlify.app also.

npm NPM npms.io (quality) Libraries.io dependency status for latest release Maintenance

npm.io

Installation

npm install koa-router-with-directory

Usage

call attachDirToRouter before start koa server

import Koa from "koa";
import Router from "koa-router";
import { attachDirToRouter } from "koa-router-with-directory";
import * as path from "path";

const router = new Router();

const app = new Koa();
const port = 8080;

attachDirToRouter(router, path.join(__dirname, "routes/"))
  .then((rrouter) => {
    app.use(router.routes());
    app.use(router.allowedMethods());
    app.listen(port, () => {
      console.log(`listening ${port}`);
    });
  });

the project directory should be like below.

project
|- routes
| |- some
| | |_ path
| |   |_ index.js
| |
| |_ another
|   |_ path
|     |_ index.js
|
|_ server.js

routed files should be named "index.js" and have one or more methods named get|post|put|delete.

import { Context } ffrom "koa";
export function get(ctx: Context){}
export function post(ctx: Context){}
export function put(ctx: Context){}
export function Delete(ctx: Context){}
1.12.0

4 months ago

1.11.1

4 months ago

1.11.0

4 months ago

1.10.0

2 years ago

1.9.0

2 years ago

1.8.0

2 years ago

1.7.0

3 years ago

1.6.0

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago