Installations
npm install koa-send
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>= 8
Node Version
12.18.0
NPM Version
6.14.4
Score
95.9
Supply Chain
100
Quality
82.3
Maintenance
100
Vulnerability
100
License
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Developer
koajs
Download Statistics
Total Downloads
149,189,248
Last Day
41,983
Last Week
537,247
Last Month
3,184,598
Last Year
37,575,559
GitHub Statistics
427 Stars
131 Commits
85 Forks
8 Watching
5 Branches
39 Contributors
Package Meta Information
Latest Version
5.0.1
Package Id
koa-send@5.0.1
Size
5.30 kB
NPM Version
6.14.4
Node Version
12.18.0
Publised On
08 Jul 2020
Total Downloads
Cumulative downloads
Total Downloads
149,189,248
Last day
-71.5%
41,983
Compared to previous day
Last week
-31.9%
537,247
Compared to previous week
Last month
-9.3%
3,184,598
Compared to previous month
Last year
7.4%
37,575,559
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
koa-send
Static file serving middleware.
Installation
1$ npm install koa-send
Options
maxage
Browser cache max-age in milliseconds. (defaults to0
).immutable
Tell the browser the resource is immutable and can be cached indefinitely. (defaults tofalse
).hidden
Allow transfer of hidden files. (defaults tofalse
).root
Root directory to restrict file access.index
Name of the index file to serve automatically when visiting the root location. (defaults to none).gzip
Try to serve the gzipped version of a file automatically whengzip
is supported by a client and if the requested file with.gz
extension exists. (defaults totrue
).brotli
Try to serve the brotli version of a file automatically whenbrotli
is supported by a client and if the requested file with.br
extension exists. (defaults totrue
).format
If notfalse
(defaults totrue
), 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/
.setHeaders
Function to set custom headers on response.extensions
Try to match extensions from passed array to search for file when no extension is sufficed in URL. First found is served. (defaults tofalse
)
Root path
Note that root
is required, defaults to ''
and will be resolved,
removing the leading /
to make the path relative and this
path must not contain "..", protecting developers from
concatenating user input. If you plan on serving files based on
user input supply a root
directory from which to serve from.
For example to serve files from ./public
:
1app.use(async (ctx) => { 2 await send(ctx, ctx.path, { root: __dirname + '/public' }); 3})
To serve developer specified files:
1app.use(async (ctx) => { 2 await send(ctx, 'path/to/my.js'); 3})
setHeaders
The function is called as fn(res, path, stats)
, where the arguments are:
res
: the response object.path
: the resolved file path that is being sent.stats
: the stats object of the file that is being sent.
You 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.
If you want to edit any other header, simply set them before calling send
.
Example
1const send = require('koa-send'); 2const Koa = require('koa'); 3const app = new Koa(); 4 5// $ GET /package.json 6// $ GET / 7 8app.use(async (ctx) => { 9 if ('/' == ctx.path) return ctx.body = 'Try GET /package.json'; 10 await send(ctx, ctx.path); 11}) 12 13app.listen(3000); 14console.log('listening on port 3000');
License
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/koajs/.github/SECURITY.md:1
- Info: Found linked content: github.com/koajs/.github/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/koajs/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/koajs/.github/SECURITY.md:1
Reason
2 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 3
Reason
Found 10/29 approved changesets -- score normalized to 3
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/koajs/send/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/koajs/send/ci.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 15 are checked with a SAST tool
Score
5.1
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More