Ver código fonte

Merge remote-tracking branch 'upstream/new-reflector'

Nikolay Suslov 7 anos atrás
pai
commit
aba42cf642
5 arquivos alterados com 118 adições e 17 exclusões
  1. 23 9
      lib/nodejs/reflector.js
  2. 69 1
      lib/nodejs/vwf.js
  3. 1 1
      public/index.html
  4. 2 1
      public/web/lib/app.js
  5. 23 5
      support/client/lib/vwf.js

+ 23 - 9
lib/nodejs/reflector.js

@@ -1,3 +1,4 @@
+"use strict";
 // reflector.js
 // 
 
@@ -11,18 +12,30 @@ function parseSocketUrl( socket ) {
 
     try
     {
-        var referer = require('url')
+        var query = require('url')
             .parse(socket.handshake.url)
             .query;
-        referer = require('querystring')
-            .parse(referer)
+       var referer = require('querystring')
+            .parse(query)
             .pathname;
+        var resObj = require('querystring')
+        .parse(query)
+        .path;
+
         var namespace = referer;
         if(!namespace) return null;
         if (namespace[namespace.length - 1] != "/")
             namespace += "/";
 
-        return parseurl.Process( namespace );
+        let parsedPath = JSON.parse(resObj);
+            
+        if (parsedPath) {
+            return parsedPath
+        }
+        // else {
+        //     return parseurl.Process(namespace);
+        // } 
+
        
     }
     catch (e)
@@ -54,9 +67,9 @@ function GetNow( ) {
 
 function OnConnection( socket ) {
 
-    var processedURL = parseSocketUrl( socket );
-
-    if (processedURL == null) {
+    let resObj = parseSocketUrl( socket );
+    
+    if (resObj == null) {
 
         setInterval(function() {
 
@@ -79,6 +92,7 @@ function OnConnection( socket ) {
         return
     }
 
+    let processedURL = resObj.path;
     //get instance for new connection
     var namespace = GetNamespace( processedURL );
     if ( namespace == undefined ) {
@@ -86,8 +100,8 @@ function OnConnection( socket ) {
     }
 
     //prepare for persistence request in case that's what this is
-    var loadInfo = GetLoadForSocket( processedURL );
-    var saveObject = persistence.LoadSaveObject( loadInfo );
+    var loadInfo = resObj.loadInfo //GetLoadForSocket( processedURL );
+    var saveObject = resObj.saveObject //persistence.LoadSaveObject( loadInfo );
 	   
     //if it's a new instance, setup record 
     if( !global.instances[ namespace ] ) {

+ 69 - 1
lib/nodejs/vwf.js

@@ -1,9 +1,11 @@
+"use strict";
 // vwf.js
 // This file contains the functions that handle the top level parsing and responses to
 // requests for the VWF nodeJS server.
 
 var parseurl = require( './parse-url' ),
     serve = require( './serve' ),
+    persistence = require( './persistence' ),
     servehandler = require( './serve-handler' ),
     helpers = require( './helpers' ),
     application = require( './application' ),
@@ -170,6 +172,70 @@ function HandleWebAppRequest(request, response) {
     return res;
 }
 
+function parseUrlForReflector( pathName ) {
+
+    try
+    {
+        var namespace = pathName;
+        if(!namespace) return null;
+        if (namespace[namespace.length - 1] != "/")
+            namespace += "/";
+
+        return parseurl.Process( namespace );
+       
+    }
+    catch (e)
+    {
+        return null;
+    }
+}
+
+function GetLoadForSocket( processedURL ) {
+    if ( processedURL[ 'private_path' ] ) {
+        return persistence.GetLoadInformation( processedURL );
+    }
+    return { 'save_name': undefined, 'save_revision': undefined, 'explicit_revision': undefined, 'application_path': undefined };
+}
+
+
+function HandleReflectorRequest(request, response) {
+    //var updatedURL = url.parse(request.url).pathname;
+
+   // var address = request.headers.host;
+    var res = false;
+
+    if (request.method === 'POST' && request.url === '/parseurl') {
+        let body = [];
+        request.on('data', (chunk) => {
+          body.push(chunk);
+        }).on('end', () => {
+          body = Buffer.concat(body).toString();
+          let pathUrl = JSON.parse(body);
+          let refPath = parseUrlForReflector( pathUrl.url );
+
+        //prepare for persistence request in case that's what this is
+        let loadInfo = GetLoadForSocket( refPath );
+        let saveObject = persistence.LoadSaveObject( loadInfo );
+
+        let resObj = {
+            path: refPath,
+            loadInfo: loadInfo,
+            saveObject: saveObject
+        }
+          //console.log(resObj);
+        let json = JSON.stringify(resObj);
+         response.writeHead(200, {"Content-Type": "application/json"});
+          response.end(json);
+        });
+      } else {
+        //response.statusCode = 404;
+        //response.end();
+      }
+
+    return res;
+}
+
+
 // Serve is the top level function for serving requests. It first attempts to 
 // serve the request based on parsing the incoming URL.
 // If that fails, it continues to attempt to serve the request as a 'proxy' request,
@@ -178,7 +244,9 @@ function HandleWebAppRequest(request, response) {
 // directory structure.
 // If all that fails, serve up a 404 response since the request was not handled.
 function Serve( request, response ) {
-    var handledRequest = HandleParsableRequest( request, response );
+    var handledRequest = HandleReflectorRequest( request, response );
+    if ( ! ( handledRequest ) ) {
+        handledRequest = HandleParsableRequest( request, response ); }
     if ( ! ( handledRequest ) ) {
         handledRequest = HandleProxyRequest( request, response );
     }

+ 1 - 1
public/index.html

@@ -109,7 +109,7 @@
             </div>
             <div id="reflectorMenu">
                 <div id="reflectorSelect" class="mdc-text-field mdc-text-field--upgraded">
-                    <input id="currentReflector" type="text" class="mdc-text-field__input" id="my-text-field" aria-controls="my-text-field-helper-text">
+                    <input id="currentReflector" type="text" class="mdc-text-field__input" id="my-text-field" aria-controls="my-text-field-helper-text" style="width:250px;">
                     <label for="my-text-field" class="mdc-text-field__label">Reflector</label>
                     <div class="mdc-text-field__bottom-line"></div>
                   </div>

+ 2 - 1
public/web/lib/app.js

@@ -10,6 +10,7 @@ class WebApp {
                 window.location.pathname.lastIndexOf("/")),
             secure: window.location.protocol === "https:",
             reconnection: false,
+            path:'',
             transports: ['websocket']
         }
 
@@ -18,7 +19,7 @@ class WebApp {
         this.initReflectorServer();
 
         //window.location.host
-        var socket = io.connect(window.location.protocol + "//" + this.currentReflector, this.options);
+        var socket = io.connect(this.currentReflector, this.options);
 
         var self = this;
 

+ 23 - 5
support/client/lib/vwf.js

@@ -805,7 +805,24 @@
 
             // Load the application.
 
-            this.ready( application );
+            var url = window.location.origin + '/parseurl';
+            let path = window.location.pathname.slice( 1, window.location.pathname.lastIndexOf("/") );
+            var data = {url: path};
+
+            fetch(url, {
+            method: 'POST', // or 'PUT'
+            body: JSON.stringify(data), 
+            headers: new Headers({
+                'Content-Type': 'application/json'
+            })
+            }).then(res => res.json())
+            .catch(error => console.error('Error:', error))
+            .then(response => {
+                console.log('Success:', response);
+                this.ready( application, response);
+            });
+
+            
 
         };
 
@@ -813,7 +830,7 @@
 
         /// @name module:vwf.ready
 
-        this.ready = function( component_uri_or_json_or_object ) {
+        this.ready = function( component_uri_or_json_or_object, path ) {
 
             // Connect to the reflector. This implementation uses the socket.io library, which
             // communicates using a channel back to the server that provided the client documents.
@@ -830,7 +847,8 @@
                     query: {
                         pathname: window.location.pathname.slice( 1,
                             window.location.pathname.lastIndexOf("/") ),
-                        appRoot: "./public"
+                        appRoot: "./public",
+                        path: JSON.stringify(path)
                       },
                     // query: 'pathname=' + window.location.pathname.slice( 1,
                     //     window.location.pathname.lastIndexOf("/") ),
@@ -852,8 +870,8 @@
 
                     //window.location.host
             var host = localStorage.getItem('lcs_reflector'); 
-            if(!host) host = window.location.host;       
-            socket = io.connect( window.location.protocol + "//" + host, options );
+            if(!host) host = window.location.origin;       
+            socket = io.connect( host, options );
                     
 
                 } else {  // Ruby Server -- only supports socket.io 0.6