Monday 25 February 2019

Why koa is wrong?

Koa has been created for years but it will never be the next generation of express.Why?Mostly it is because of the wrongly designed middleware.Middleware we can know by name that it is a bridge between two entities.But koa's middleware is not. It is a container that wraps every so-called middlewares added later into the first one.so make the first so-called middleware most significant.The first middleware can modify every changes made by the middlewares inside it.That makes the middlewares inside the first one almost meaning less.​It makes koa very vulnerable to middleware attacks and will destroy security models you build for your web sites.​And also koa wastes a lot of efforts in rewriting express middlewares.​In effect, to achieve promises and async/await syntax with express is very simple, even no need to write almost all middlewares for express.​You can easily check it with vig:​import { VHandler } from "vig";let app = require('express')();const handler = new VHandler();​handler.set({prefix: '/demo',urls: ['/', '/hello'],routers: {get: async (req, res, scope) => {res.send('Hello world!');}}});​handler.attach(app);​app.listen(10000, function () {console.log('server running on http://localhost:10000');});​

Submitted February 25, 2019 at 09:50AM by calidion

No comments:

Post a Comment