koa icon indicating copy to clipboard operation
koa copied to clipboard

koa 3.0 roadmap

Open dead-horse opened this issue 6 years ago • 75 comments

There are lots of PRs are blocked due to breaking change, and maybe it's time to make a plan for koa 3.0 now, if anyone has other suggestion, please post in this issue. :)

  • https://github.com/koajs/koa/issues/1044
  • https://github.com/koajs/koa/issues/1008
  • https://github.com/koajs/koa/issues/998
  • https://github.com/koajs/koa/issues/904
  • https://github.com/koajs/koa/pull/1011

dead-horse avatar Dec 24 '17 06:12 dead-horse

Is it to early to create a v3 branch? I have some spare time coming up and wouldn’t mind doing some work.

fl0w avatar Dec 24 '17 09:12 fl0w

All these pending PRs are not so emergency to me, so if anyone has any thoughts or some feature / refactor required, post in the issue to help us decide when to start create v3 branch. :)

dead-horse avatar Dec 24 '17 12:12 dead-horse

How about officially dropping support for < node.js 8?

fl0w avatar Dec 26 '17 19:12 fl0w

koa-compose could rewrite using async/await

iyuq avatar Dec 27 '17 03:12 iyuq

totally rewrite using TypeScript

iyuq avatar Dec 27 '17 03:12 iyuq

I'm personally against introducing TypeScript, adding external typings should be easy enough for those in need.

fl0w avatar Dec 27 '17 09:12 fl0w

How about officially dropping support for < node.js 8?

koa-compose could rewrite using async/await

@fl0w @iyuq according to community practice, engines support should always follow the Node.js release schedule :)

marswong avatar Jan 08 '18 14:01 marswong

totally rewrite using TypeScript

like what @fl0w said above, just one more thing: koa is quite vary from eggexpress and any other framework. It's just a pure http request middleware close to Node.js as you can see. So we can just feel free to write in pure JavaScript, follow the traditional convention and trust Node.js :)

marswong avatar Jan 08 '18 14:01 marswong

if you have any breaking changes you'd like to introduce, please state them now :)

jonathanong avatar Jan 31 '18 05:01 jonathanong

Let's announce EOL for Koa v1.

fl0w avatar Feb 12 '18 12:02 fl0w

How about support HTTP/2 ? https://nodejs.org/api/http2.html

zhangxiang958 avatar Mar 29 '18 11:03 zhangxiang958

@zhangxiang958 koa already support it since 2.3.0, u can simply setup a koa app over HTTP/2 like this:

const fs = require('fs');
const http2 = require('http2');
const Koa = require('koa');

const app = new Koa();

app.use(ctx => {
  ctx.body = 'Hello Koa'; // or any other stream
});

const options = {
  key: fs.readFileSync('xxx.key'),
  cert: fs.readFileSync('xxx.crt'),
};
const server = http2.createSecureServer(options, app.callback());

server.listen(443);

marswong avatar Mar 30 '18 02:03 marswong

How about publish koa and official middleware module under @koajs/ ?

hiroqn avatar May 09 '18 14:05 hiroqn

Adjust naming to follow WHATWG URL Standard. Eg: request.path should be request.pathname etc

urugator avatar May 13 '18 12:05 urugator

I think #1044 has already been solved by this commit

likegun avatar May 17 '18 01:05 likegun

I think context.res and context.req are not good names and they make people confused with context.response and context.request. Is it better if we can name them behind NodeJS names, so context.res becomes context.serverResponse and context.req becomes context.incomingRequest?

tiendq avatar Jul 18 '18 13:07 tiendq

@tiendq I completely agree! I keep mixing up req/request and res/response. I vote for something like

{
req:<koa request>,
res:<koa response>:,
raw:{
   req:<node request>,
   res:<node response>
}}

ng- avatar Aug 06 '18 21:08 ng-

How to access the http2 stream on ctx object to push assets to client using koa? It this supported right now?

damianobarbati avatar Oct 07 '18 09:10 damianobarbati

I second @damianobarbati , would be great to get an implementation snippet that displays the compatibility and its usage. For example, would the stream be accessible through ctx.res.stream?

I've been seeing a bit of chatter on HTTP/2 support for Koa - I agree that we don't need to define config just to "enable" out of the box. What we do need however, is an interface to utilize HTTP/2, let's say if the request type is HTTP/2, maybe context could be formed at this stage.

I believe that the moment the Koa community takes a stance on HTTP/2, this would promote its usage for the next generation of servers built using Koa. To me, this is a great step forward.

What I envision, as a mode of compatibility and usage, is to add ctx.stream if the request is in an HTTP/2 context. As a start, we could yield the benefits of pushing from the stream and get a grip on how to manage push streams without ending the connection prematurely.

mike-tobia avatar Oct 08 '18 00:10 mike-tobia

How about publish koa and official middleware module under @koajs/ ?

Why not simply @koa/?

tajnymag avatar Oct 10 '18 11:10 tajnymag

Here is my little suggestions

  • ~~#1044 because more and more people are using next/nuxt applications (or maybe not by I am…)~~
  • and as said by @Tajnymag a @koa namespace can be useful:
    • @koa/cors is already namespaced
    • it will be clearer what are the official middleware
    • for new adopter, it makes more easy what to safely start with. IMO “official” guaranties that it plays nicely with the framework and will be maintained over time
  • optional some typescript types if needed as this language is getting more and more traction

[EDIT]

In fact everything's working perfectly. The application doesn't crash and we have a warn.
Up to us to fix that by sending the headers before next/nuxt rendering.

Hiswe avatar Oct 16 '18 03:10 Hiswe

Note, I am not privileged to make this decision. This is my personal opinion.

I'd like to chime in that I agree that namespace:ing npm-releases under npm:@koa is a good idea.

One or two caveats thought.

  1. Only for packages that reside in github:@koajs
  2. Don't namespace Koa core, i.e. npm i koa still resolves as expected.

Bug reports for 3rd party packages often end up in @koajs/koa#issues, which is burdensome for both maintainers and the user. This might clear things up a bit.

I also haven't considered possible implications of moving the packages (e.g. does npm have tooling for moving origins?).

fl0w avatar Oct 16 '18 09:10 fl0w

+1 on #1044

maticrivo avatar Oct 17 '18 11:10 maticrivo

Please do normal error handling. The ability to set content type

mytecor avatar Jan 19 '19 17:01 mytecor

+1 on #998

catsalive avatar Apr 05 '19 20:04 catsalive

I suggest #1326

dolsup avatar Apr 26 '19 06:04 dolsup

Is there any timeline or schedule for 3.0?

Hanggi avatar May 23 '19 02:05 Hanggi

Need some help?

libook avatar Sep 17 '19 02:09 libook

I think removing next parameter from middleware and just awaiting all middleware can be most useful breaking change in 3.0. Debugging something like bellow is a nightmare:

app.use(async (ctx, next) => {
 // ... do something
 await next();
// ... do some more staff
})
app.use(async (ctx, next) => {
 // ... do something
 await next();
// ... do some more staff
})

while removing next will make composition simple and koa-compose will not be needed:

// koa-compose will not be needed, just do this:
  async handleRequest(ctx) {
    const res = ctx.res;
    res.statusCode = 404;
   try {
     for (const handler of this.middleware) {
        await handler(ctx);
     }
    respond(ctx);
   } catch (err) {
     ctx.onerror(err);
  } finally {
    // any finalisation logic here
  }
}

if something need to be guaranteed last handler then it can use events or better composition and .state

tinovyatkin avatar Oct 15 '19 12:10 tinovyatkin

@tinovyatkin What if you need to do something after the next() call? For example, I'm using this scenario in multipart middleware:

import {parse} from "then-busboy"
import {unlink} from "promise-fs"

const unlinkFile = ({path}) => unlink(path)

const methods = ["post", "put"]

async function multipart(ctx, next) {
  if (!methods.includes(ctx.method.toLowerCase())) {
    return next()
  }

  if (!ctx.is("multipart/form-data")) {
    return next()
  }

  const body = await parse(ctx.req)

  ctx.request.body = body

  await next()

  // Cleanup files
  return Promise.all(Array.from(body.files.values()).map(unlinkFile))
    .catch(err => err.code !== "ENOENT" && Promise.reject(err))
}

export default multipart

How can I do so without next() as simple as this?

octet-stream avatar Oct 15 '19 12:10 octet-stream