{"id":13779823,"url":"https://github.com/koajs/resourcer","last_synced_at":"2025-10-19T13:31:34.277Z","repository":{"id":19775161,"uuid":"23033565","full_name":"koajs/resourcer","owner":"koajs","description":"A simple resource directory mounter for koa.","archived":false,"fork":false,"pushed_at":"2017-10-15T05:51:29.000Z","size":9,"stargazers_count":35,"open_issues_count":1,"forks_count":3,"subscribers_count":57,"default_branch":"master","last_synced_at":"2025-09-17T23:59:27.793Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/koajs.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","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":"2014-08-17T05:00:47.000Z","updated_at":"2024-07-20T00:13:47.000Z","dependencies_parsed_at":"2022-07-23T13:47:50.808Z","dependency_job_id":null,"html_url":"https://github.com/koajs/resourcer","commit_stats":null,"previous_names":["pebble/koa-resourcer"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/koajs/resourcer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fresourcer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fresourcer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fresourcer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fresourcer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koajs","download_url":"https://codeload.github.com/koajs/resourcer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fresourcer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279529640,"owners_count":26185718,"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","status":"online","status_checked_at":"2025-10-18T02:00:06.492Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-08-03T18:01:09.637Z","updated_at":"2025-10-19T13:31:33.960Z","avatar_url":"https://github.com/koajs.png","language":"JavaScript","funding_links":[],"categories":["Middleware"],"sub_categories":[],"readme":"\n# resourcer\n\nA simple resource directory mounter for [koa](http://koajs.com).\n\n[![Build Status](https://travis-ci.org/koajs/resourcer.svg?branch=master)](https://travis-ci.org/koajs/resourcer)\n[![Coverage Status](https://img.shields.io/coveralls/koajs/resourcer.svg)](https://coveralls.io/r/koajs/resourcer)\n[![npm](http://img.shields.io/npm/v/koa-resourcer.svg)](https://www.npmjs.org/package/koa-resourcer)\n\n```js\nvar koa = require('koa');\nvar resource = require('koa-resourcer');\n\nvar app = koa();\nresource(app, join(__dirname, 'resources') [, callback])\napp.listen();\n```\n\nThe idea behind `koa-resourcer` is complete modularity within your\nkoa app. Each directory can be a stand-alone koa application with all\nit's own tests, docs, dependencies, etc. `koa-resourcer` makes it easy to\nmount these apps if you follow a simple directory pattern.\n\n- [directory structure](#directory-structure)\n- [config.json](#configjson)\n- [callbacks](#callbacks)\n- [installation](#installation)\n- [development](#development)\n- [sponsored by](#sponsored-by)\n- [license](#license)\n\n### Directory structure\n\nSay we have the following directory structure:\n\n```\nresources/\n|-- v1/users/\n|   |-- config.json\n|   `-- app.js\n|-- v1/products/\n|   |-- config.json\n|   |-- makefile\n|   |-- index.js\n|   |-- lib/\n|   |   `-- utils.js\n|   `-- test/\n|       `-- index.js\n`-- v2/users/\n    |-- config.json\n    `-- fun.js\n```\n\nWe have three independent apps here. `v1/users/app.js`, `v1/products/index.js` and\n`v2/users/fun.js`. We could use `koa-mount` directly and be done with it but\nthat requires the parent application to know where all the apps are and the paths\non which they should be mounted.\n\n```js\nvar koa = require('koa')\nvar mount = require('koa-mount')\nvar app = koa()\n\nvar v1users = require('./v1/users/app.js')\napp.use(mount('v1/users/', v1users))\n\nvar v2users = require('./v2/users/fun.js')\napp.use(mount('v2/users/', v2users))\n\nvar v1products = require('./v1/products/')\napp.use(mount('v1/products/', v1products))\n\n// and so on, and so on, for each of your sub apps....\n\napp.listen()\n```\n\nWith `koa-resourcer` you let your directory structure and some simple\nconfig files do the talking for you, keeping your parent application\npeacefully oblivious.\n\n```js\nvar koa = require('koa')\nvar join = require('path').join\nvar resource = require('koa-resourcer')\nvar app = koa()\n\nresource(app, join(__dirname, 'resources'))\n\napp.listen()\n```\n\n#### config.json\n\nEach application directory must contain a `config.json` file. The `config.json` file\nis used to discover the location of the application source code. This information\nis stored in it's `source` property.\n\n```js\n// resources/v1/users/config.json\n\n{ \"source\": \"app.js\" }\n```\n\nBy relying on the directory structure to determine route paths, `koa-resourcer`\nwill automatically mount `app.js` on `/v1/users/` for you. If this path isn't\nquite what you want, `koa-resourcer` also supports configuring your path names in\nthe `config.json` files.\n\n```js\n// resources/v1/users/config.json\n\n{ \"source\": \"app.js\", \"path\": \"user\" }\n```\n\nBy adding the `path` property to our configuration, `koa-resourcer` will now mount\nthe app on `/v1/user/`.\n\n\n### Callbacks\n\nIf you pass a callback function as the third argument to `koa-resourcer`, it\nwill be executed for each mounted application passing an object containing\nthe path and application resource.\n\n```js\nvar koa = require('koa')\nvar join = require('path').join\nvar resource = require('koa-resourcer')\nvar app = koa()\n\nresource(app, join(__dirname, 'resources'), function(o){\n  console.log('mounted %s', o.path, o.resource)\n})\n\napp.listen()\n```\n\n### Installation\n\n```\nnpm install koa-resourcer --save\n```\n\n### Development\n\n#### running tests\n\n- `make test` runs tests\n- `make test-cov` runs tests + test coverage\n- `make open-cov` opens test coverage results in your browser\n\n#### verbose logging\n\n`koa-resourcer` supports the `debug` module for help during development.\nEnable verbose logging by setting your `DEBUG` env variable like so:\n\n````\nDEBUG=koa-resourcer* npm test\n```\n\n## Sponsored by\n\n[Pebble Technology!](https://www.pebble.com)\n\n## License\n\n[MIT](https://github.com/koajs/resourcer/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fresourcer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoajs%2Fresourcer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fresourcer/lists"}