{"id":21332257,"url":"https://github.com/stultuss/koa-mini-server","last_synced_at":"2026-05-20T19:34:14.507Z","repository":{"id":41735702,"uuid":"231730468","full_name":"stultuss/koa-mini-server","owner":"stultuss","description":"Quickly create a minimal Koa server.","archived":false,"fork":false,"pushed_at":"2022-12-06T15:43:52.000Z","size":577,"stargazers_count":0,"open_issues_count":14,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-22T13:51:40.814Z","etag":null,"topics":["koa","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stultuss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-04T08:12:57.000Z","updated_at":"2020-02-21T08:05:47.000Z","dependencies_parsed_at":"2023-01-24T02:01:17.751Z","dependency_job_id":null,"html_url":"https://github.com/stultuss/koa-mini-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stultuss%2Fkoa-mini-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stultuss%2Fkoa-mini-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stultuss%2Fkoa-mini-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stultuss%2Fkoa-mini-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stultuss","download_url":"https://codeload.github.com/stultuss/koa-mini-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243809886,"owners_count":20351407,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["koa","typescript"],"created_at":"2024-11-21T22:46:26.687Z","updated_at":"2026-05-20T19:34:09.485Z","avatar_url":"https://github.com/stultuss.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Koa Mini Server\n=========================\n\n\u003e Quickly create a minimal Koa server.\n\n### Feature\n\n- [x] 跨域处理\n- [x] 参数验证\n- [x] 日志输出\n- [x] 封装缓存库\n- [x] 封装数据库\n- [x] 数据映射模型\n- [ ] 灰度\n- [ ] 限流\n\n## Usage\n\n```bash\nnpm install\nnpm start\n```\n\n## How to begin\n\n1. create a `demo.api.ts` file in `~/src/apis/`\n\n``` typescript\nimport * as joi from '@hapi/joi';\nimport {Context as KoaContext} from 'koa';\nimport {AbstractBase, MiddlewareNext, RequestSchema} from '../abstract/AbstractBase';\nimport {ErrorFormat} from '../../common/exception/ErrorFormat';\nimport {CacheFactory} from '../../common/cache/CacheFactory.class';\nimport {DemoService} from '../../service/demo.service';\n\ninterface RequestParams {\n    id: number,\n    name: string\n}\n\nclass Demo extends AbstractBase {\n    \n    constructor() {\n        super();\n        this.method = 'all'; // 'all' | 'post' | 'get'\n        this.uri = '/v1/demo';\n        this.type = 'application/json; charset=utf-8';\n        this.schema = {\n            id: joi.number().required(),\n            name: joi.string().required()\n        };\n    }\n    \n    public async handle(ctx: KoaContext, req: RequestSchema, next: MiddlewareNext): Promise\u003cany\u003e {\n        const params = req.aggregatedParams as RequestParams;\n        \n        // 返回结构\n        const response: any = params;\n        \n        // 测试报错\n        if (params.name == 'error') {\n            throw new ErrorFormat(20001, \"default error message\");\n        }\n        \n        // 测试缓存\n        if (params.name == 'redis') {\n            response.incr = await CacheFactory.instance().getCache().incr('INCR');\n        }\n        \n        // 测试数据库 / orm\n        if (params.name == 'orm') {\n            const demoModel = await DemoService.getDemo(params.id);\n            response.demo = await demoModel.format();\n        }\n        \n        return response;\n    };\n}\n\nmodule.exports = new Demo();\n```\n\n2. Run `tsc` and `node ./build/index.js`\n\n3. The website server worked,  `http://127.0.0.1:8001/v1/demo` .\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstultuss%2Fkoa-mini-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstultuss%2Fkoa-mini-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstultuss%2Fkoa-mini-server/lists"}