GithubHelp home page GithubHelp logo

kaelzhang / express-to-koa Goto Github PK

View Code? Open in Web Editor NEW
20.0 4.0 5.0 33 KB

Use express middlewares in Koa2, the one that really works.

License: Other

JavaScript 100.00%
koa koa2 middleware converter express

express-to-koa's Introduction

Build Status Coverage

express-to-koa

Use express middlewares in Koa2 (not support koa1 for now), the one that REALLY WORKS.

  • Handle koa2 http status code, which fixes the common issue that we always get 404 with koa-connect
  • Handle express middlewares that contains .pipe(res), such as express.static which based on send

Usage

const e2k = require('express-to-koa')

// Some express middleware
const devMiddleware = require('webpack-dev-middleware')(compiler, {
  publicPath,
  quiet: true
})

const app = new Koa()
app.use(e2k(devMiddleware))

What Kind of Express Middlewares are Supported?

NEARLY ALL express middlewares built with best practices.

TL;NR

express-to-koa does not support all arbitrary express middlewares, but only for those who only uses Express-Independent APIs like res.write and res.end, i.e. the APIs that node http.ServerResponse provides.

However, if a middleware uses APIs like res.send or something, express-to-koa will do far too much work to convert those logic to koa2, which is not easier than creating both express and koa2 from 0 to 1.

So, it is a good practice to write framework-agnostic middlewares or libraries.

Supported Middlewares

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.