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

koa #15

Open
adriangrigore opened this issue Apr 14, 2015 · 15 comments
Open

koa #15

adriangrigore opened this issue Apr 14, 2015 · 15 comments
Labels

Comments

@adriangrigore
Copy link

Consider adding support for koa?

@jprichardson
Copy link
Collaborator

Sure. PR welcomed.

On Tuesday, April 14, 2015, Adrian Grigore [email protected] wrote:

Consider adding support for koa?


Reply to this email directly or view it on GitHub
#15.

Simple & Secure Bitcoin Wallet: https://www.coinbolt.com
Bitcoin / JavaScript: http://cryptocoinjs.com
Follow JP Richardson on Twitter: https://twitter.com/jprichardson

@nahtnam
Copy link

nahtnam commented Apr 27, 2017

+1 for this, would love to see support for koa.

@nahtnam
Copy link

nahtnam commented Apr 27, 2017

@jprichardson I am working on a PR, and it seems to work, but I get these errors in the log.

reload.js:90 WebSocket connection to 'ws://localhost:3000/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

I don't know this is because reload is waiting for the server to reboot or if there is an error in the websocket implementation with koa. Here is the entire log.

reload.js:7 Reload Script Loaded
reload.js:25 Page Loaded - Calling webSocketWaiter
reload.js:87 Waiting for socket
reload.js:48 Socket Opened
reload.js:68 Socket Closed - Calling webSocketWaiter
reload.js:87 Waiting for socket
reload.js:90 WebSocket connection to 'ws://localhost:3000/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED // IS THIS BECAUSE THE SERVER IS RESTARTING OR BECAUSE OF AN ERROR?
(anonymous) @ reload.js:90
reload.js:80 Event {isTrusted: true, type: "error", target: WebSocket, currentTarget: WebSocket, eventPhase: 2…}
reload.js:68 Socket Closed - Calling webSocketWaiter
reload.js:87 Waiting for socket
reload.js:90 WebSocket connection to 'ws://localhost:3000/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED // IS THIS BECAUSE THE SERVER IS RESTARTING OR BECAUSE OF AN ERROR?
(anonymous) @ reload.js:90
reload.js:80 Event {isTrusted: true, type: "error", target: WebSocket, currentTarget: WebSocket, eventPhase: 2…}
reload.js:68 Socket Closed - Calling webSocketWaiter
reload.js:87 Waiting for socket
reload.js:90 WebSocket connection to 'ws://localhost:3000/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED // IS THIS BECAUSE THE SERVER IS RESTARTING OR BECAUSE OF AN ERROR?
(anonymous) @ reload.js:90
reload.js:80 Event {isTrusted: true, type: "error", target: WebSocket, currentTarget: WebSocket, eventPhase: 2…}
reload.js:68 Socket Closed - Calling webSocketWaiter
reload.js:87 Waiting for socket
reload.js:48 Socket Opened
reload.js:54 Reloaded
reload.js:33 Navigated away from the current URL
Navigated to http://localhost:3000/
reload.js:7 Reload Script Loaded
reload.js:25 Page Loaded - Calling webSocketWaiter
reload.js:87 Waiting for socket
reload.js:48 Socket Opened

@alallier
Copy link
Owner

alallier commented Apr 27, 2017

It should wait for the server to be running after a restart of the server before it tries to open a socket connection. It those cases where the error is printing is the server started? The code you are using would be helpful to help you debug

@alallier alallier added this to the v2.0.0 milestone Apr 27, 2017
@nahtnam
Copy link

nahtnam commented Apr 27, 2017

@alallier So I got it working, but there is one problem. Koa makes use of async/await which pushes the node requirement to 7.6.0. I dont think it would be a good idea to include it in this library, unless you want to transpile the code.

@ghost
Copy link

ghost commented Apr 28, 2017

The travis-ci tests try to build v4 of node, so I don't think that bumping it up to 7.6 is going to be a good idea. I'm only using 6.10.2 at the moment because that is the stable release, and that is what most people would be using

@ghost
Copy link

ghost commented Apr 28, 2017

Although, it installed on my version of node (6.10.2) so maybe you can use koa, just not the async. on https://www.npmjs.com/package/koa it says that you can use either the async function or the common function. Maybe this will work, just using the common function rather than the async.

@alallier alallier removed this from the v2.0.0 milestone Jun 25, 2017
@ghost
Copy link

ghost commented Jul 20, 2017

@alallier What are we doing about this?

@nahtnam
Copy link

nahtnam commented Jul 20, 2017

Sorry, I have turned around and started working in other languages. I do not think I will be able to complete this.

@ghost
Copy link

ghost commented Jul 20, 2017

@adriangrigore Do you think that you can do anything about this?

@alallier
Copy link
Owner

alallier commented Jul 20, 2017

@nahtnam That is okay. Do you mind if we take your work (from #90) and adapt and build from it?

@nahtnam
Copy link

nahtnam commented Jul 20, 2017

Of course not, please go ahead and do anything you would like. I could also answer any questions you have.

Most of the code you will need is here: 6c15d71

It would be a good idea to tell anyone using koa to put the middleware near the top in the README.

@AckerApple
Copy link

I studied Koa to find it can process middleware just as Express processes middleware.

The problem with reload, is it straps itself to Express and/or to Koa INSTEAD of offering a middleware plugin to allow others to strap it to there.

I solved this in my fork by removing Express and offering a middleware function as seen here: https://github.com/AckerApple/reload/blob/master/lib/reload.js#L47

@adriangrigore
Copy link
Author

adriangrigore commented Jul 21, 2017

@Yamboy1 Sorry, didn't get the chance to even build anything with koa, was just experimenting at the time.I don't think I can be of much use.

@mkalam-alami
Copy link

mkalam-alami commented Mar 15, 2020

Here is a small wrapper to pretend koa-router is actually an Express server:

function wrapRouterForReload(router) {
  const wrappedRouter = function() { }
  wrappedRouter.get = (route, callback) => {
    router.get(route, (ctx) => {
      callback(undefined, {
        type: (type) => ctx.type = type,
        send: (body) => ctx.body = body
      });
    });
  }
  return wrappedRouter;
}

You can then do:

const wrappedRouter = wrapRouterForReload(router);
reloader = reload(wrappedRouter);

Obviously this may break with future reload versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants