Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
tasyncexpress
Advanced tools
Readme
monkeypatch express/router/layer so you can write async handler
app.post('/user', ({body})=>userDao.insert(body));
app.post('/user/login', async (req,res)=>{
const user = await userDao.getByMail(req.body.mail);
if(user.password == req.body.password){
req.session = {userId:user.id};
return user;
}
return false;
});
app.get('/user/:id', ({params:{id}})=>userDao.getById(params.id));
app.get('/blogpost/:title', async ({params:{title}})=>{
var post = await mysql.query('SELECT * FROM blogposts WHERE title = *', title);
post.author = await mysql.query('SELECT * FROM user WHERE id = ?', post.authorId);
return post;
})
// and all your existing code also still works, still run sum tests before go blind to production
require('express/lib/router/layer').prototype.handle_request = function handle(req, res, next) {
var fn = this.handle;
if (fn.length > 3) { return next(); }
try {
var promise = fn(req, res, next);
if (typeof (promise) === 'object' && typeof (promise.catch) === 'function' && typeof (promise.then) === 'function') {
promise.then((data) => {
try {
if (data !== undefined){
if(typeof(data) == 'string'){
res.send(data);
}else if(typeof(data)==='object'){
res.json(data);
}
}
} catch (err) {/*ignore error*/ }
});
promise.catch(next);
}
} catch (err) { next(err); }
};
there are different aproaches: similar aproach with different opinion about handling the resolve value of that promise.
replacing the 'all','use','del',[verb] methods on the routers.
Create a subclass
let you wrap every handler into a promise handling method.
At this point I am not clear what aproach will be in general the best, as still more projects get started with express then with koa.js I would also like to see a change in version express 5. Using this patch module, the code with express get much cleaner, so that there is very little reason to switch to an other framework. In this module you see the opinion of not just catching the error but also returning JSON.
FAQs
monkeypatch express/router/layer so you can write async handler
The npm package tasyncexpress receives a total of 0 weekly downloads. As such, tasyncexpress popularity was classified as not popular.
We found that tasyncexpress 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.