
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
@mest-fe/porters-middleware
Advanced tools
供 [Porters](https://github.com/mest-io/porters) 项目使用的 Lambda 中间件,适用于 [Nitric](https://nitric.io/docs/installation) 环境。
供 Porters 项目使用的 Lambda 中间件,适用于 Nitric 环境。
标准化外部调用参数,将定时任务平台或手动调用提供的参数序列化后提供给 Lambda。在调用时,单个 Lambda 可能同时被并行调用多次, 每个函数内部请按当前序列号来决定需要处理的任务批次。
函数参数来自于 request body
,序列化后可参考:
version
: 当前调用版本,hash 字符串current
: 当前 Lambda 工作的位置,相对于并发数的序列号,从 1 开始,应当小于 concurrency
concurrency
: 当前调用版本的并发数ignoreRetry
: 是否忽略重试使用后 Lambda 需要验证 header 中 token 字符串是否合法,如果合法则继续调用,否则返回 401。
在 Lambda 函数中嵌套使用中间件:
mainApi.post('/api', async ctx => {
const handler = () => {
// do something
}
await scheduleMiddleware(ctx, handler)
})
多个中间件请按参数调用嵌套:
const authHandler = next => scheduleMiddleware(next, handler)
await authMiddleware(ctx, authHandler)
业务中出现需要中断进程的错误,可及时捕获并返回错误信息。
const request = () => {
throw new Error('something wrong')
}
await scheduleMiddleware(ctx, () => {
try {
request()
} catch (err) {
return HTTP.badGateway(ctx, `${err.message}`)
}
})
多数场景中,Lambda 并不需要因为单个错误中断流程,可以将错误信息记录到日志,并继续执行。
const request = async () => {
const result = await Promise.all([...])
const errors = result.filter(item => item.status === 'rejected')
// 大于一定数量的错误,直接抛出业务异常
if (errors.length > 5) {
throw new Error(errors.map(item => item.reason)
.join('\n'))
}
// 允许范围内,统计警告并继续运行
if (errors.length > 0) {
errors.forEach(item => globalWarning.add(item.reason))
}
}
FAQs
供 [Porters](https://github.com/mest-io/porters) 项目使用的 Lambda 中间件,适用于 [Nitric](https://nitric.io/docs/installation) 环境。
The npm package @mest-fe/porters-middleware receives a total of 22 weekly downloads. As such, @mest-fe/porters-middleware popularity was classified as not popular.
We found that @mest-fe/porters-middleware demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.