0.0.26 • Published 1 month ago
wittyna v0.0.26
wittyna
简介
一个基于KOA的服务端框架。对比 nestjs, midway 等框架,wittyna更加轻量,灵活,简单。
特性
- 控制器类、装饰器轻松实现路由分发
- 装饰器参数校验
- 中间件支持,内置的中间件有:
- body
- response
- session
- static
- mongodb
安装
npm install wittyna
使用
import {
startServer,
responseMiddleWare,
bodyMiddleWare,
Controller,
Body,
Post,
BodyFile,
Get,
Query,
Put,
ResponseError,
Required,
} from 'wittyna';
import { sessionMiddleWare, staticMiddleWare } from 'wittyna';
import { Context } from 'koa';
import { dirname } from 'path';
@Controller('hello')
export class HelloController {
@Get('123')
async get(@Query('a') b: number, ctx: Context): Promise<unknown> {
const session = ctx.session as unknown as { count: number };
ctx.cookies.set('a', '1', { httpOnly: false });
session.count = session.count || 0;
session.count++;
console.log(session.count);
console.log(
ctx.request.hostname,
ctx.request.originalUrl,
ctx.request.path,
ctx.request.querystring
);
return { count: session.count, b: typeof b };
}
}
startServer({
port: 3000,
controllers: [new HelloController()],
routerPrefix: '/api',
middlewares: [
staticMiddleWare({
root: dirname(new URL(import.meta.url).pathname),
pathPrefix: '/public',
}),
sessionMiddleWare({
redisOptions: {
host: 'localhost',
port: 6379,
db: 0,
},
}),
responseMiddleWare(),
bodyMiddleWare(),
],
});
0.0.24
1 month ago
0.0.25
1 month ago
0.0.26
1 month ago
0.0.20
11 months ago
0.0.21
11 months ago
0.0.22
11 months ago
0.0.23
11 months ago
0.0.14
11 months ago
0.0.15
11 months ago
0.0.16
11 months ago
0.0.17
11 months ago
0.0.18
11 months ago
0.0.13
12 months ago
0.0.12
1 year ago
0.0.11
1 year ago
0.0.10
1 year ago
0.0.9
1 year ago
0.0.8
1 year ago
0.0.7
1 year ago
0.0.6
1 year ago
0.0.5
1 year ago
0.0.4
1 year ago
0.0.3
1 year ago
0.0.2
1 year ago
0.0.1
1 year ago