You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2016/12/09 00:51:48 UTC

cordova-plugins git commit: CB-10958: Retain the `src` attribute of the `content` element when it already points to localhost

Repository: cordova-plugins
Updated Branches:
  refs/heads/master 34ee8598e -> 08ab173a3


CB-10958: Retain the `src` attribute of the `content` element when it already points to localhost

 This closes #24


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugins/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugins/commit/08ab173a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugins/tree/08ab173a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugins/diff/08ab173a

Branch: refs/heads/master
Commit: 08ab173a3ee16f6a5ba6638a33d4ee298e87ec1b
Parents: 34ee859
Author: Andreas Kohn <an...@gmail.com>
Authored: Thu Mar 24 15:33:34 2016 +0100
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Thu Dec 8 16:54:18 2016 -0800

----------------------------------------------------------------------
 .gitignore                               |  2 ++
 local-webserver/package.json             | 36 +++++++++++++++++++++++++++
 local-webserver/plugin.xml               |  2 +-
 local-webserver/scripts/after_install.js | 16 +++++++-----
 4 files changed, 49 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/08ab173a/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index fd29596..fb8b6c8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
 # OS X
 .DS_Store
+# NPM
+*/node_modules

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/08ab173a/local-webserver/package.json
----------------------------------------------------------------------
diff --git a/local-webserver/package.json b/local-webserver/package.json
new file mode 100644
index 0000000..9c99957
--- /dev/null
+++ b/local-webserver/package.json
@@ -0,0 +1,36 @@
+{
+  "name": "cordova-labs-local-webserver",
+  "version": "2.3.1",
+  "description": "Cordova Local Web Server Plugin",
+  "cordova": {
+    "id": "cordova-labs-local-webserver",
+    "platforms": [
+      "ios"
+    ]
+  },
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/Collaborne/cordova-plugins.git"
+  },
+  "keywords": [
+    "cordova",
+    "local web server",
+    "ecosystem:cordova",
+    "cordova-ios"
+  ],
+  "engines": [
+    {
+      "name": "cordova-ios",
+      "version": ">=4.0.0-dev"
+    }
+  ],
+  "author": "",
+  "license": "Apache-2.0",
+  "bugs": {
+    "url": "https://github.com/Collaborne/cordova-plugins/issues"
+  },
+  "homepage": "https://github.com/Collaborne/cordova-plugins#readme",
+  "dependencies": {
+    "urijs": "^1.17.1"
+  }
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/08ab173a/local-webserver/plugin.xml
----------------------------------------------------------------------
diff --git a/local-webserver/plugin.xml b/local-webserver/plugin.xml
index f8bc820..42b3f9f 100644
--- a/local-webserver/plugin.xml
+++ b/local-webserver/plugin.xml
@@ -86,7 +86,7 @@
         <framework src="libz.dylib" />
 
         <info>
-        Your content tag in config.xml now points to a http://localhost:0 location (randomized port), e.g. &lt;content src="http://localhost:0" /&gt;
+        If your &lt;content&gt; element did not already point to 'http://localhost[:port]', it will now point to a http://localhost:0 location (randomized port), e.g. &lt;content src="http://localhost:0" /&gt;
         WARNING: For localStorage and IndexedDB persistence, you must choose a non-randomized port (between 1 and 49152, to avoid the ephemeral port range 49152 to 65535 on iOS).
     </info>
 

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/08ab173a/local-webserver/scripts/after_install.js
----------------------------------------------------------------------
diff --git a/local-webserver/scripts/after_install.js b/local-webserver/scripts/after_install.js
index d138091..c135276 100644
--- a/local-webserver/scripts/after_install.js
+++ b/local-webserver/scripts/after_install.js
@@ -22,9 +22,9 @@
 // This script modifies the project root's config.xml
 // The <content> tag "src" attribute is modified to point to http://localhost:0
 
-var content_src_value = "http://localhost:0";
 var fs = require('fs');
 var path = require('path');
+var URI = require('urijs');
 var old_content_src_value;
 
 module.exports = function(context) {
@@ -37,11 +37,15 @@ module.exports = function(context) {
     var content_tags = etree.findall('./content[@src]');
     if (content_tags.length > 0) {
         old_content_src_value = content_tags[0].get('src');
-        var backup_json = path.join(context.opts.plugin.dir, 'backup.json');
-        var backup_value = { content_src : old_content_src_value };
-        fs.writeFileSync(backup_json, JSON.stringify(backup_value));
-
-        content_tags[0].set('src', content_src_value);
+        var content_src = URI.parse(old_content_src_value);
+        if (content_src.hostname !== 'localhost') {
+            var backup_json = path.join(context.opts.plugin.dir, 'backup.json');
+            var backup_value = { content_src : old_content_src_value };
+            fs.writeFileSync(backup_json, JSON.stringify(backup_value));
+
+            // XXX: Should we retain the name of the index file here?
+            content_tags[0].set('src', 'http://localhost:0');
+        }
     }
 
     var altcontentsrcTag = etree.findall("./preference[@name='AlternateContentSrc']");


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org