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.
@idan-loo/middleware
Advanced tools
Create your own middlewares to divide a large logic into serveral wares
Create your own middlewares to divide a large logic into serveral wares.
It is inspired by the middleware system of Koa
# with npm
npm install --save @idan-loo/middleware
# with yarn
yarn add @idan-loo/middleware
import { executorOf } from '@idan-loo/middleware'
const mw1 = async (ctx, next) => {
ctx.name = 'mw1'
await next()
}
const mw2 = async (ctx, next) => {
ctx.name = 'mw2'
await next()
}
const mw3 = async (ctx, next) => {
ctx.name = 'mw3'
await next()
}
const exec = executorOf({ name: 'test' })
await exec(mw1, mw2, mw3)
Each middleware should return a Promise object. You can simply add an async
keyword in front of the function declation, or just return next()
.
import { Next } from '@idan-loo/middleware'
type Context = {
name: string,
}
const mw1 = async (ctx: Context, next: Next) => {
ctx.name = 'mw1'
return next()
}
const mw2 = async (ctx: Context, next: Next) => {
ctx.name = await anAsyncAction()
await next()
}
const mw3 = async (ctx: Context, next: Next) => {
await next()
ctx.name = 'after next'
}
If you want to go on executing the next middlewares, you should call next()
manually.
import { executorOf } from '@idan-loo/middleware'
const mw1 = async (ctx: Context, next: Next) => {
ctx.name = 'mw1'
return next()
}
const mw2 = async (ctx: Context) => {
ctx.name = 'mw2'
}
const mw3 = async (ctx: Context, next: Next) => {
ctx.name = 'mw3'
return next()
}
const exec = executorOf({ name: 'test' })
// mw3 won't be executed because mw2 doesn't call the next method
exec(mw1, mw2, mw3)
FAQs
Create your own middlewares to divide a large logic into serveral wares
The npm package @idan-loo/middleware receives a total of 52 weekly downloads. As such, @idan-loo/middleware popularity was classified as not popular.
We found that @idan-loo/middleware 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.