Skip to content
This repository

Move app init so any getHttpServer call returns initialized app instance... #625

Merged
merged 1 commit into from over 1 year ago

2 participants

Scott Isao Yagi
Scott

The idea here is that some containers just want the app instance, but we were only initializing it if you called start(). This update moves the initialization into the getter to ensure the server instance you get is always initialized, but only initialized once.

Isao Yagi

+1

Isao Yagi

oh should you be returning here

return app.listen(...)

so it doesn't proceed to line 639/642?

Scott mojit0 merged commit 0367e9e into from
Scott mojit0 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Oct 12, 2012
Scott mojit0 Move app init so any getHttpServer call returns initialized app insta…
…nce.
71246de
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 12 additions and 9 deletions. Show diff stats Hide diff stats

  1. +12 9 lib/mojito.js
21 lib/mojito.js
@@ -460,6 +460,14 @@ MojitoServer.prototype.close = function() {
460 460 * @return {http.Server} The node.js http.Server (or subtype) instance.
461 461 */
462 462 MojitoServer.prototype.getHttpServer = function() {
  463 +
  464 + // Only configure the server once by checking for a startup time.
  465 + if (!this._startupTime) {
  466 + this._startupTime = new Date().getTime();
  467 + this._configureAppInstance(this._app, this._options);
  468 + }
  469 +
  470 + // Return the http.Server instance, properly configured above.
463 471 return this._app;
464 472 };
465 473
@@ -612,21 +620,15 @@ MojitoServer.prototype.setLogWriter = function(writer) {
612 620 MojitoServer.prototype.start = function(cb) {
613 621
614 622 var logger,
615   - app = this._app,
  623 + app = this.getHttpServer(), // Get initialized app instance.
616 624 callback = cb || Mojito.NOOP;
617 625
618 626 if (this._options.verbose) {
619 627 libutils.warn('Starting Mojito Application');
620 628 }
621 629
622   - // Only configure the server once by checking for a startup time.
623   - if (!this._startupTime) {
624   - this._startupTime = new Date().getTime();
625   - this._configureAppInstance(this._app, this._options);
626   - }
627   -
628 630 try {
629   - this._app.listen(this._options.port, null, function(err) {
  631 + app.listen(this._options.port, null, function(err) {
630 632 // NOTE that we're passing the private app instance here!!!
631 633 // TODO: Verify we want to do this, as opposed to passing 'this'.
632 634 callback(err, app);
@@ -635,7 +637,8 @@ MojitoServer.prototype.start = function(cb) {
635 637 callback(err);
636 638 }
637 639
638   - // Return the application instance for certain server containers to use.
  640 + // NOTE that we're passing the private app instance here!!!
  641 + // TODO: Verify we want to do this, as opposed to passing 'this'.
639 642 return app;
640 643 };
641 644

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.