Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Simple asynchronous middleware pattern.
npm install throwback --save
Compose asynchronous (promise-returning) functions.
const { compose } = require('throwback')
const fn = compose([
async function (ctx, next) {
console.log(1)
try {
await next()
} catch (err) {
console.log('throwback', err)
}
console.log(4)
},
async function (ctx, next) {
console.log(2)
return next()
}
])
// Callback runs at the end of the stack, before
// the middleware bubbles back to the beginning.
fn({}, function (ctx) {
console.log(3)
ctx.status = 404
})
Tip: In development mode, debug
mode will throw errors when you do something unexpected. In production, faster non-error code paths are used.
Build a micro HTTP server!
const { createServer } = require('http')
const finalhandler = require('finalhandler') // Example only, not compatible with single `ctx` arg.
const { compose } = require('throwback')
const app = compose([
function ({ req, res }, next) {
res.end('Hello world!')
}
])
createServer(function (req, res) {
return app({ req, res }, finalhandler())
}).listen(3000)
Did you know next(ctx?)
accepts an optional ctx
argument which will override ctx
for all following middleware functions? This enables advanced functionality such as Request
cloning and retries in popsicle
.
async function retryRequest (req, next) {
let retries = 5
while (retries--) {
try {
const res = await next(req.clone())
return res
} catch (e) {
continue
}
}
throw new Error('Retry limit exceeded')
}
Built for servie
and inspired by koa-compose
.
MIT
FAQs
Simple asynchronous middleware pattern
We found that throwback 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.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.