{"id":13779917,"url":"https://github.com/koajs/send","last_synced_at":"2025-05-13T22:05:48.704Z","repository":{"id":12463539,"uuid":"15127744","full_name":"koajs/send","owner":"koajs","description":"Transfer static files","archived":false,"fork":false,"pushed_at":"2024-10-12T23:54:25.000Z","size":112,"stargazers_count":427,"open_issues_count":19,"forks_count":86,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-09T19:14:52.040Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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}},"created_at":"2013-12-12T05:28:54.000Z","updated_at":"2024-11-26T20:38:37.000Z","dependencies_parsed_at":"2024-11-06T09:36:36.319Z","dependency_job_id":null,"html_url":"https://github.com/koajs/send","commit_stats":{"total_commits":123,"total_committers":35,"mean_commits":"3.5142857142857142","dds":0.8048780487804879,"last_synced_commit":"05b2eebeda85fe07a0d3ab5b80bc985c178f2ba1"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fsend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fsend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fsend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fsend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koajs","download_url":"https://codeload.github.com/koajs/send/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248094987,"owners_count":21046770,"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-03T18:01:10.535Z","updated_at":"2025-05-13T22:05:48.686Z","avatar_url":"https://github.com/koajs.png","language":"TypeScript","readme":"# [**@koa/send**](https://github.com/koajs/send)\n\n[![NPM version][npm-image]][npm-url]\n![Build Status][github-action-image]\n[![Test coverage][coveralls-image]][coveralls-url]\n[![License][license-image]][license-url]\n[![Downloads][downloads-image]][downloads-url]\n\n[npm-image]: https://img.shields.io/npm/v/@koa/send.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/@koa/send\n[github-action-image]: https://github.com/koajs/send/actions/workflows/ci.yml/badge.svg?style=flat-square\n[coveralls-image]: https://img.shields.io/coveralls/koajs/send.svg?style=flat-square\n[coveralls-url]: https://coveralls.io/r/koajs/send?branch=master\n[license-image]: http://img.shields.io/npm/l/koa-send.svg?style=flat-square\n[license-url]: LICENSE\n[downloads-image]: http://img.shields.io/npm/dm/koa-send.svg?style=flat-square\n[downloads-url]: https://npmjs.org/package/koa-send\n\nKoa static file serving middleware.\n\n\u003e Notice: We recommend using `@koa/send` for installation, as both `koa-send` and `@koa/send` refer to the same module. However, in our next major versions bumps, we will deprecate `koa-send` and only maintain the module under `@koa/send`.\n\n## Install\n\n[![NPM](https://nodei.co/npm/@koa/send.png?downloads=true)](https://nodei.co/npm/@koa/send)\n\n```js\n$ npm i @koa/send\n```\n\n## Options\n\n- `maxage` Browser cache max-age in milliseconds. (defaults to `0`).\n- `immutable` Tell the browser the resource is immutable and can be cached indefinitely. (defaults to `false`).\n- `hidden` Allow transfer of hidden files. (defaults to `false`).\n- [`root`](#root-path) Root directory to restrict file access.\n- `index` Name of the index file to serve automatically when visiting the root location. (defaults to none).\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. (defaults to `true`).\n- `format` If not `false` (defaults to `true`), format the path to serve static file servers and not require a trailing slash for directories, so that you can do both `/directory` and `/directory/`.\n- [`setHeaders`](#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`)\n\n### Root path\n\nNote that `root` is required, defaults to `''` and will be resolved,\nremoving the leading `/` to make the path relative and this\npath must not contain \"..\", protecting developers from\nconcatenating user input. If you plan on serving files based on\nuser input supply a `root` directory from which to serve from.\n\nFor example to serve files from `./public`:\n\n```js\napp.use(async (ctx) =\u003e {\n  await send(ctx, ctx.path, { root: __dirname + \"/public\" });\n});\n```\n\nTo serve developer specified files:\n\n```js\napp.use(async (ctx) =\u003e {\n  await send(ctx, \"path/to/my.js\");\n});\n```\n\n### setHeaders\n\nThe function is called as `fn(res, path, stats)`, where the arguments are:\n\n- `res`: the response object.\n- `path`: the resolved file path that is being sent.\n- `stats`: the stats object of the file that is being sent.\n\nYou should only use the `setHeaders` option when you wish to edit the `Cache-Control` or `Last-Modified` headers, because doing it before is useless (it's overwritten by `send`), and doing it after is too late because the headers are already sent.\n\nIf you want to edit any other header, simply set them before calling `send`.\n\n## Example\n\n```js\nconst send = require(\"@koa/send\");\nconst Koa = require(\"koa\");\nconst app = new Koa();\n\n// $ GET /package.json\n// $ GET /\n\napp.use(async (ctx) =\u003e {\n  if (\"/\" == ctx.path) return (ctx.body = \"Try GET /package.json\");\n  await send(ctx, ctx.path);\n});\n\napp.listen(3000);\nconsole.log(\"listening on port 3000\");\n```\n\n## License\n\n[MIT](/LICENSE)\n","funding_links":[],"categories":["Middleware","仓库"],"sub_categories":["中间件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fsend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoajs%2Fsend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fsend/lists"}