@medomino-170/koa-server
v0.0.21
Published
### 示例
Downloads
14
Readme
快速生成 nodejs(koa) 后端服务
示例
import { createServer, API, RouteItem } from "../src";
interface ExtensKey {
body: {
__token: {
user: string;
};
};
headers: {
token: string;
};
extend: {
compress: boolean;
};
}
type Base = API<ExtensKey>;
type WrapRoute<T extends Record<string, any> = {}> = RouteItem<ExtensKey, T>;
const get: WrapRoute<{ lql: string }> = {
method: "get",
async callback({ body: { __token, lql }, ctx }) {
console.log(__token, lql, ctx.query, ctx.search, ctx.request.body);
return 123;
},
};
const api: Base["api"] = {
"/api": {
"/v/": get,
},
};
const intercept: Base["intercept"] = {
"/api/(.*)": async (_ctx, next) => {
await next();
},
};
createServer({
base: {
port: 8000,
},
api: {
api,
intercept,
},
});