{"id":13511886,"url":"https://github.com/koajs/static","last_synced_at":"2025-05-12T13:26:32.232Z","repository":{"id":10115431,"uuid":"12182834","full_name":"koajs/static","owner":"koajs","description":"Static file server middleware","archived":false,"fork":false,"pushed_at":"2025-05-05T18:00:01.000Z","size":78,"stargazers_count":1144,"open_issues_count":11,"forks_count":112,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-05-08T20:12:13.339Z","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2013-08-17T17:45:51.000Z","updated_at":"2025-05-03T18:11:39.000Z","dependencies_parsed_at":"2024-01-12T23:42:51.792Z","dependency_job_id":"3921788d-8824-460e-aee8-0d9f9f7c9ded","html_url":"https://github.com/koajs/static","commit_stats":{"total_commits":106,"total_committers":25,"mean_commits":4.24,"dds":0.7735849056603774,"last_synced_commit":"8a03f8db492616e539fdda58466ac89650332d96"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fstatic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fstatic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fstatic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fstatic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koajs","download_url":"https://codeload.github.com/koajs/static/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253199469,"owners_count":21870081,"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":[],"created_at":"2024-08-01T03:01:16.719Z","updated_at":"2025-05-12T13:26:32.212Z","avatar_url":"https://github.com/koajs.png","language":"JavaScript","readme":"# koa-static\n\n[![NPM version][npm-image]][npm-url]\n[![Build status][travis-image]][travis-url]\n[![Test coverage][coveralls-image]][coveralls-url]\n[![License][license-image]][license-url]\n[![Downloads][downloads-image]][downloads-url]\n\nKoa static file serving middleware, wrapper for [`koa-send`](https://github.com/koajs/send).\n\n## Installation\n\n```bash\n$ npm install koa-static\n```\n\n## API\n\n```js\nimport Koa from \"koa\"; // CJS: require('koa');\nimport serve from \"koa-static\"; // CJS: require('koa-static')\nconst app = new Koa();\napp.use(serve(root, opts));\n```\n\n- `root` root directory string. nothing above this root directory can be served\n- `opts` options object.\n\n### Options\n\n- `maxage` Browser cache max-age in milliseconds. defaults to 0\n- `hidden` Allow transfer of hidden files. defaults to false\n- `index` Default file name, defaults to 'index.html'\n- `defer` If true, serves after `return next()`, allowing any downstream middleware to respond first.\n- `gzip` Try to serve the gzipped version of a file automatically when gzip is supported by a client and if the requested file with .gz extension exists. defaults to true.\n- `brotli` Try to serve the brotli version of a file automatically when brotli is supported by a client and if the requested file with .br extension exists (note, that brotli is only accepted over https). defaults to true.\n- [setHeaders](https://github.com/koajs/send#setheaders) Function to set custom headers on response.\n- `extensions` Try to match extensions from passed array to search for file when no extension is sufficed in URL. First found is served. (defaults to `false`).  e.g. `['html']`\n\n## Example\n\n```js\nconst serve = require(\"koa-static\");\nconst Koa = require(\"koa\");\nconst app = new Koa();\n\n// $ GET /package.json\napp.use(serve(\".\"));\n\n// $ GET /hello.txt\napp.use(serve(\"test/fixtures\"));\n\n// or use absolute paths\napp.use(serve(__dirname + \"/test/fixtures\"));\n\napp.listen(3000);\n\nconsole.log(\"listening on port 3000\");\n```\n\n### See also\n\n- [koajs/conditional-get](https://github.com/koajs/conditional-get) Conditional GET support for koa\n- [koajs/compress](https://github.com/koajs/compress) Compress middleware for koa\n- [koajs/mount](https://github.com/koajs/mount) Mount `koa-static` to a specific path\n\n## License\n\nMIT\n\n[npm-image]: https://img.shields.io/npm/v/koa-static.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/koa-static\n[github-tag]: http://img.shields.io/github/tag/koajs/static.svg?style=flat-square\n[github-url]: https://github.com/koajs/static/tags\n[travis-image]: https://img.shields.io/travis/koajs/static.svg?style=flat-square\n[travis-url]: https://travis-ci.org/koajs/static\n[coveralls-image]: https://img.shields.io/coveralls/koajs/static.svg?style=flat-square\n[coveralls-url]: https://coveralls.io/r/koajs/static?branch=master\n[license-image]: http://img.shields.io/npm/l/koa-static.svg?style=flat-square\n[license-url]: LICENSE\n[downloads-image]: http://img.shields.io/npm/dm/koa-static.svg?style=flat-square\n[downloads-url]: https://npmjs.org/package/koa-static\n[gittip-image]: https://img.shields.io/gittip/jonathanong.svg?style=flat-square\n[gittip-url]: https://www.gittip.com/jonathanong/\n","funding_links":[],"categories":["JavaScript","Middleware","仓库","Node.js, koa"],"sub_categories":["中间件","Utilites"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fstatic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoajs%2Fstatic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fstatic/lists"}