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

http server instance is not passed to mocks, prevents WebSocket mocks. #2302

Closed
go1dfish opened this issue Oct 13, 2014 · 2 comments
Closed

Comments

@go1dfish
Copy link
Contributor

The ember-cli server task passes options to each middleware, but currently it is not possible for middleware to get access to the http server instance (in fact it is created after the server middleware is initialized)

This makes it difficult to setup mocks that initialize a ws.Server to provide a web socket service.

Changing ExpressServer.start to this seems to work without issue for me:

start: function(options) {
  var ui             = this.ui;
  this.app = require('express')();
  this.setupHttpServer();

  options.project     = this.project;
  options.watcher     = this.watcher;
  options.ui          = this.ui;
  options.httpServer  = this.httpServer

  this.processAppMiddlewares(options);
  this.processAddonMiddlewares(options);

  return this.listen(options.port, options.host)
    .then(function() {
      ui.writeLine('Serving on http://' + options.host + ':' + options.port);
    })
    .catch(function() {
      throw new SilentError('Could not serve on http://' + options.host + ':' + options.port + '. It is either in use or you do not have permission.');
    });
}

I just have to modify my mocks/index.js in my project to pass the options on to my individual middleware functions.

Is there an example of a better way to do web socket mocks anywhere else? Or a way to extend/reopen/override default tasks like ExpressServer?

@rwjblue
Copy link
Member

rwjblue commented Oct 13, 2014

This change seems perfectly fine with me. Please submit a PR (with a test that confirms httpServer is present in the options passed through to the middlewares).

Closing this in favor of your future PR. 😉

@benlesh
Copy link

benlesh commented Oct 15, 2014

👍 Need this today.

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

No branches or pull requests

3 participants