Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Koa instead of Express #107

Closed
kherock opened this issue Jan 24, 2018 · 9 comments · Fixed by #392
Closed

Use Koa instead of Express #107

kherock opened this issue Jan 24, 2018 · 9 comments · Fixed by #392

Comments

@kherock
Copy link
Collaborator

kherock commented Jan 24, 2018

I've contributed enough to this project to know it decently well and I think it could benefit pretty massively from async/await and Koa's support for processing the response body after middleware is run.

I'm just opening this issue seeking an opinion on potentially including a Babel build pipeline if I were to write for Koa 2. However it looks like Travis is only doing tests for Node >= 6, so Koa 1 would also work fine if we want to avoid Babel. This isn't intended to be just changes for the sake of using newer features; it really should make things a lot more readable and approachable for adding new features such as versioning.

@n1ru4l
Copy link
Collaborator

n1ru4l commented Jan 24, 2018

Hey there!

First of all I love koa and async/await.
I also noticed that the code base is quite messy and not optimal.

We also should support all LTS node versions.
if we would do this could use koa 2 with generator functions (http://node.green/#ES2015-functions-generators). Once LTS for 6 is dropped we could easily change those to async functions.

I think a babel build step would be a bit of an overkill 🤔

What do you think @leontastic? I would definitely love to see this, however I do not have all the time to convert/rewrite the application.

@kherock
Copy link
Collaborator Author

kherock commented Jan 24, 2018

I'd be down to do most of it, I haven't been too strapped for time.

Node 4 supports most of the important ES2015 features (nvm spread and rest params are pretty useful, and its EOL is in April) including generators so I think it would be reasonable to target v6 and use either Koa 1 or Koa 2 with the deprecation warnings disabled.

@leontastic
Copy link
Collaborator

leontastic commented Jan 25, 2018

Code is very messy. I want to refactor it myself but I also haven't found the bandwidth to do so.

Not opposed to using Koa or Babel at all. I think introducing a build step is a worthy trade-off to allow us to take advantage of next-gen syntax features. As long as we keep the build config simple, so it doesn't introduce maintenance headaches down the road.

@kherock
Copy link
Collaborator Author

kherock commented Jan 25, 2018

Even if we go the Babel route, I recently realized that it isn't entirely feasible since a large portion of the Koa 2 ecosystem expects Node.js 7.6+, which means that we'd have to choose what dependencies we use carefully. We'd need to depend on versions written for Koa 1.x and we'd only be able to update once Node 6 exits LTS.

I think it's reasonable just to write for Koa 1 for now bearing in mind that it will need to be adapted for Koa 2 later. If you do it right it's pretty painless, I've done it for a much larger project than this when it got bumped up to Node 8.

@n1ru4l
Copy link
Collaborator

n1ru4l commented Jan 25, 2018

What parts of koa 2 couldn't we use? Also I think babel would be overkill.

@kherock
Copy link
Collaborator Author

kherock commented Jan 25, 2018

I just checked and it looks like most of the important ones are safe (koa, koa-compose, and koa-router) so we'd probably actually be fine. I also kind of agree that Babel is overkill since the only feature we actually need is async/await.

@leontastic
Copy link
Collaborator

Could just use Promise.coroutine from Bluebird to get async/await-like syntax without needing a babel transform. I'd love to introduce Bluebird anyway to convert async logic to promises.

@n1ru4l
Copy link
Collaborator

n1ru4l commented Jan 25, 2018

Koa supports generator function as a async await replacement.

@kherock
Copy link
Collaborator Author

kherock commented Jan 25, 2018

Promise.coroutine is essentially the main export of co which comes with Koa. I think we should be able to get by without involving Bluebird.

@kherock kherock mentioned this issue Feb 13, 2019
24 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants