{"id":15046592,"url":"https://github.com/ccjoe/koa-pattern","last_synced_at":"2026-02-08T04:32:09.532Z","repository":{"id":79616784,"uuid":"99777665","full_name":"ccjoe/koa-pattern","owner":"ccjoe","description":"pattern middleware for koa, a koa middleware that support mvc and rest","archived":false,"fork":false,"pushed_at":"2017-08-15T07:06:00.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-11T06:01:45.609Z","etag":null,"topics":["koa2","middleware","mvc","restful"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ccjoe.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-09T07:21:23.000Z","updated_at":"2017-08-11T04:25:43.000Z","dependencies_parsed_at":"2023-04-09T22:01:39.914Z","dependency_job_id":null,"html_url":"https://github.com/ccjoe/koa-pattern","commit_stats":{"total_commits":4,"total_committers":2,"mean_commits":2.0,"dds":0.25,"last_synced_commit":"f7cab1374e0e83fccf935060b029dbf5b1d8f800"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ccjoe/koa-pattern","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccjoe%2Fkoa-pattern","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccjoe%2Fkoa-pattern/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccjoe%2Fkoa-pattern/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccjoe%2Fkoa-pattern/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ccjoe","download_url":"https://codeload.github.com/ccjoe/koa-pattern/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccjoe%2Fkoa-pattern/sbom","scorecard":{"id":269161,"data":{"date":"2025-08-11","repo":{"name":"github.com/ccjoe/koa-pattern","commit":"f7cab1374e0e83fccf935060b029dbf5b1d8f800"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/4 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-17T12:55:08.101Z","repository_id":79616784,"created_at":"2025-08-17T12:55:08.101Z","updated_at":"2025-08-17T12:55:08.101Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29220459,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-08T03:18:47.732Z","status":"ssl_error","status_checked_at":"2026-02-08T03:15:31.985Z","response_time":57,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["koa2","middleware","mvc","restful"],"created_at":"2024-09-24T20:53:16.278Z","updated_at":"2026-02-08T04:32:09.511Z","avatar_url":"https://github.com/ccjoe.png","language":"JavaScript","readme":"# koa-pattern\n\n[![Build status][travis-image]][travis-url]\n[![NPM version][npm-image]][npm-url]\n[![NPM downloads][npm-downloads-image]][npm-url]\n[![Dependency Status][david-image]][david-url]\n[![License][license-image]][license-url]\n\nA Really Simple koa middleware that support mvc and rest , including template rendering middleware.\n\n\u003e **Note:** This middleware is for `koa@2`. koa@1 test not recovery.\n\n## Installation\n\n```\n$ npm install koa-pattern\n$ npm run example\n```\n\n## Templating engines\n\n`koa-pattern` is using [consolidate](https://github.com/tj/consolidate.js) for veiw render under the hood.\n\n[List of supported engines](https://github.com/tj/consolidate.js#supported-template-engines)\n\n## Example\n\n```js\nvar pattern = require('koa-pattern');\n\napp.use(pattern({\n        dir: __dirname,\n        prefix: '',     // url prefix or virtual directory\n        mvcPrefix: 'pages',//if undefine or '',null,  not run mvc  pattern\n        restPrefix: 'api',//if undefine or '',null,  not run rest pattern\n        //if have used others view middleware or template Engine, and has ctx.render method, can not config tmplEngine\n        tmplEngine: 'dot'//or {name:'dot', 'extension':'html'}\n    }));\n```\n* `opts.dir`: Where your ctrls \u0026 views are located. this location must direct include ctrls/views, Must be an absolute path.\n* `opts.prefix` (optional) url prefix or virtual directory\n* `opts.mvcPrefix`: url mvc prefix\n* `opts.restPrefix`: url rest prefix\n* `opts.tmplEngine`: template Engine name string or object include name and extension: {name:'dot', 'extension':'html'}\n\nFor more examples you can take a look at the [example](./example/index.js).\n\n## Demo Dir\n```\nexample\n    |-ctrls\n    |   |-user.js\n    |-views\n    |    |-user\n    |        |-index.html\n    |        |-list.html\n    |-index.js\n```\n#### `mvc pattern` HTTP GET http://localhost/pages/ctrlName/actionName\neg: `HTTP GET http://localhost/pages/user/list`\nIt will render views dir user/list.html automatic, and view's data return by ctrls/user.js list function\n\nif not `ctrlName` or `actionName`, it default `'index'`, and if not `index dir`, root view default\n\n```js\n//ctrls/user.js\nmodule.exports.list = (ctx, next) =\u003e {\n  return [{\n      userName: 'bd',\n      userNo: '007'\n  },{\n      userName: 'bd2',\n      userNo: '9527'\n  }]\n}\n```\n\n#### `rest pattern` HTTP GET/POST/PUT/DELETE  http://localhost/restPrefix/resourceName/[respration]\nRest Pattern support 2 url style to render api json data\neg:\n1. `HTTP GET/POST/PUT/DELETE http://localhost/api/user/007`\n2. `HTTP GET/POST            http://localhost/api/user/list`\n\nactually, `1` and `2` is just the same rule url\n\nand the `1` will render json by  match `HTTP method` matched function, and `007` will be url argument, eg `007` is userid,\nif not HTTP method matched function, it will match ctrls/user.js `007`/`list` methods,\nmatch rule\n```\n    'GET': 'query',\n    'POST': 'update',\n    'PUT': 'create',\n    'DELETE': 'remove'\n```\nso url 1 return `list` as below, url2 if HTTP METHOD IS GET will match `query` return\n```\nmodule.exports.list = (ctx, next) =\u003e {\n  return [{\n      userName: 'bd',\n      userNo: '007'\n  },{\n      userName: 'bd2',\n      userNo: '9527'\n  }]\n}\n\nmodule.exports.query = (ctx, next) =\u003e {\n  return {\n      userName: 'bd',\n      userNo: '007'\n  }\n}\n```\n\n#### rest and mvc pattern async supported\n```\nmodule.exports.asynclist = (ctx, next) =\u003e {\n    var data = {}\n    var kk = () =\u003e new Promise((resolve, reject) =\u003e {\n        setTimeout(function(){\n            resolve([{\n                userName: 'bd',\n                userNo: '007'\n            },{\n                userName: 'bd2',\n                userNo: '9527'\n            }])\n        },1000)\n    })\n    return kk().then((data) =\u003e {\n        return data\n    });\n}\n```\n## License\n\n[MIT](./license)\n\n[travis-image]: https://img.shields.io/travis/ccjoe/koa-pattern.svg?style=flat-square\n[travis-url]: https://travis-ci.org/ccjoe/koa-pattern\n[npm-image]: https://img.shields.io/npm/v/koa-pattern.svg?style=flat-square\n[npm-downloads-image]: https://img.shields.io/npm/dm/koa-pattern.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/koa-pattern\n[david-image]: http://img.shields.io/david/ccjoe/koa-pattern.svg?style=flat-square\n[david-url]: https://david-dm.org/ccjoe/koa-pattern\n[license-image]: http://img.shields.io/npm/l/koa-pattern.svg?style=flat-square\n[license-url]: ./license\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccjoe%2Fkoa-pattern","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fccjoe%2Fkoa-pattern","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccjoe%2Fkoa-pattern/lists"}