@@ -43,10 +43,10 @@ define(function (require, exports, module) {
4343 * baseUrl - Optional base URL (populated by the current project)
4444 * pathResolver - Function to covert absolute native paths to project relative paths
4545 * root - Native path to the project root (and base URL)
46- * nodeConnection - An active NodeConnection
46+ * nodeDomain - An initialized NodeDomain
4747 */
4848 function StaticServer ( config ) {
49- this . _nodeConnection = config . nodeConnection ;
49+ this . _nodeDomain = config . nodeDomain ;
5050 this . _onRequestFilter = this . _onRequestFilter . bind ( this ) ;
5151
5252 BaseServer . call ( this , config ) ;
@@ -61,7 +61,7 @@ define(function (require, exports, module) {
6161 * @return {boolean } true for yes, otherwise false.
6262 */
6363 StaticServer . prototype . canServe = function ( localPath ) {
64- if ( ! this . _nodeConnection . connected ( ) ) {
64+ if ( ! this . _nodeDomain . ready ( ) ) {
6565 return false ;
6666 }
6767
@@ -87,17 +87,9 @@ define(function (require, exports, module) {
8787 * @return {jQuery.Promise } Resolved by the StaticServer domain when the message is acknowledged.
8888 */
8989 StaticServer . prototype . _updateRequestFilterPaths = function ( ) {
90- if ( ! this . _nodeConnection . connected ( ) ) {
91- return ;
92- }
93-
94- var paths = [ ] ;
90+ var paths = Object . keys ( this . _liveDocuments ) ;
9591
96- Object . keys ( this . _liveDocuments ) . forEach ( function ( path ) {
97- paths . push ( path ) ;
98- } ) ;
99-
100- return this . _nodeConnection . domains . staticServer . setRequestFilterPaths ( this . _root , paths ) ;
92+ return this . _nodeDomain . exec ( "setRequestFilterPaths" , this . _root , paths ) ;
10193 } ;
10294
10395 /**
@@ -109,37 +101,14 @@ define(function (require, exports, module) {
109101 * the server is ready/failed.
110102 */
111103 StaticServer . prototype . readyToServe = function ( ) {
112- var readyToServeDeferred = $ . Deferred ( ) ,
113- self = this ;
114-
115- if ( this . _nodeConnection . connected ( ) ) {
116- this . _nodeConnection . domains . staticServer . getServer ( self . _root ) . done ( function ( address ) {
104+ var self = this ;
105+ return this . _nodeDomain . exec ( "getServer" , self . _root )
106+ . done ( function ( address ) {
117107 self . _baseUrl = "http://" + address . address + ":" + address . port + "/" ;
118- readyToServeDeferred . resolve ( ) ;
119- } ) . fail ( function ( ) {
108+ } )
109+ . fail ( function ( ) {
120110 self . _baseUrl = "" ;
121- readyToServeDeferred . reject ( ) ;
122111 } ) ;
123- } else {
124- // nodeConnection has been connected once (because the deferred
125- // resolved, but is not currently connected).
126- //
127- // If we are in this case, then the node process has crashed
128- // and is in the process of restarting. Once that happens, the
129- // node connection will automatically reconnect and reload the
130- // domain. Unfortunately, we don't have any promise to wait on
131- // to know when that happens. The best we can do is reject this
132- // readyToServe so that the user gets an error message to try
133- // again later.
134- //
135- // The user will get the error immediately in this state, and
136- // the new node process should start up in a matter of seconds
137- // (assuming there isn't a more widespread error). So, asking
138- // them to retry in a second is reasonable.
139- readyToServeDeferred . reject ( ) ;
140- }
141-
142- return readyToServeDeferred . promise ( ) ;
143112 } ;
144113
145114 /**
@@ -181,9 +150,7 @@ define(function (require, exports, module) {
181150 * Send HTTP response data back to the StaticServerSomain
182151 */
183152 StaticServer . prototype . _send = function ( location , response ) {
184- if ( this . _nodeConnection . connected ( ) ) {
185- this . _nodeConnection . domains . staticServer . writeFilteredResponse ( location . root , location . pathname , response ) ;
186- }
153+ this . _nodeDomain . exec ( "writeFilteredResponse" , location . root , location . pathname , response ) ;
187154 } ;
188155
189156 /**
@@ -209,15 +176,15 @@ define(function (require, exports, module) {
209176 * See BaseServer#start. Starts listenting to StaticServerDomain events.
210177 */
211178 StaticServer . prototype . start = function ( ) {
212- $ ( this . _nodeConnection ) . on ( "staticServer. requestFilter" , this . _onRequestFilter ) ;
179+ $ ( this . _nodeDomain ) . on ( "requestFilter" , this . _onRequestFilter ) ;
213180 } ;
214181
215182 /**
216183 * See BaseServer#stop. Remove event handlers from StaticServerDomain.
217184 */
218185 StaticServer . prototype . stop = function ( ) {
219- $ ( this . _nodeConnection ) . off ( "staticServer. requestFilter" , this . _onRequestFilter ) ;
186+ $ ( this . _nodeDomain ) . off ( "requestFilter" , this . _onRequestFilter ) ;
220187 } ;
221188
222- exports . StaticServer = StaticServer ;
189+ module . exports = StaticServer ;
223190} ) ;
0 commit comments