0.0.26 • Published 1 year 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 year ago
0.0.25
1 year ago
0.0.26
1 year ago
0.0.20
2 years ago
0.0.21
2 years ago
0.0.22
2 years ago
0.0.23
2 years ago
0.0.14
2 years ago
0.0.15
2 years ago
0.0.16
2 years ago
0.0.17
2 years ago
0.0.18
2 years ago
0.0.13
2 years ago
0.0.12
2 years ago
0.0.11
2 years ago
0.0.10
2 years ago
0.0.9
2 years ago
0.0.8
2 years ago
0.0.7
2 years ago
0.0.6
2 years ago
0.0.5
2 years ago
0.0.4
2 years ago
0.0.3
2 years ago
0.0.2
2 years ago
0.0.1
2 years ago