Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@types/koa-send
Advanced tools
@types/koa-send provides TypeScript definitions for the koa-send package, which is used to serve static files in a Koa application.
Serving Static Files
This feature allows you to serve static files from a specified path. In this example, when the user accesses the '/static' route, the server will respond with the file located at 'path/to/file.txt'.
const Koa = require('koa');
const send = require('koa-send');
const app = new Koa();
app.use(async (ctx) => {
if (ctx.path === '/static') {
await send(ctx, 'path/to/file.txt');
}
});
app.listen(3000);
Setting Root Directory
This feature allows you to set a root directory for serving static files. In this example, the server will look for 'file.txt' in the 'public' directory located in the current directory.
const Koa = require('koa');
const send = require('koa-send');
const app = new Koa();
app.use(async (ctx) => {
if (ctx.path === '/static') {
await send(ctx, 'file.txt', { root: __dirname + '/public' });
}
});
app.listen(3000);
Setting Cache Control
This feature allows you to set cache control headers for the served files. In this example, the 'maxAge' option is set to 1 hour, meaning the file will be cached for 1 hour.
const Koa = require('koa');
const send = require('koa-send');
const app = new Koa();
app.use(async (ctx) => {
if (ctx.path === '/static') {
await send(ctx, 'file.txt', { maxAge: 1000 * 60 * 60 }); // 1 hour
}
});
app.listen(3000);
@types/koa-static provides TypeScript definitions for the koa-static package, which is another middleware for serving static files in a Koa application. Unlike koa-send, koa-static is specifically designed for serving static files and directories, making it simpler to use for that purpose.
@types/serve-static provides TypeScript definitions for the serve-static package, which is used to serve static files in Express applications. While it is designed for Express, it can be used with Koa through the koa-connect package, offering similar functionality to koa-send.
npm install --save @types/koa-send
This package contains type definitions for koa-send (https://github.com/koajs/send).
Files were exported from https://www.github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/koa-send
Additional Details
These definitions were written by Peter Safranek https://github.com/pe8ter, Tomek Łaziuk https://github.com/tlaziuk.
FAQs
TypeScript definitions for koa-send
The npm package @types/koa-send receives a total of 132,797 weekly downloads. As such, @types/koa-send popularity was classified as popular.
We found that @types/koa-send demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.