1.12.4 • Published 4 months ago
koa-router-with-directory v1.12.4
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.
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.3
6 months ago
1.12.2
6 months ago
1.12.1
7 months ago
1.12.4
4 months ago
1.12.0
1 year ago
1.11.1
2 years ago
1.11.0
2 years ago
1.10.0
3 years ago
1.9.0
3 years ago
1.8.0
3 years ago
1.7.0
4 years ago
1.6.0
4 years ago
1.5.1
4 years ago
1.5.0
4 years ago
1.4.0
5 years ago
1.3.0
5 years ago
1.2.0
5 years ago
1.1.0
5 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago