├── LICENSE ├── Readme.md ├── package.json ├── plugin.xml └── scripts └── afterBuild.js /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 The App Workshop 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Meteor 1.4.1 Cordova iOS 10 Content Security Policy Web Sockets Fix 2 | 3 | That's a mouthful of a title. But it's a really simple little cordova plugin that 4 | just rewrites the ```META``` tag in your cordova build's ```platforms/ios/www/index.html``` 5 | file. 6 | 7 | This fixes an issue with meteor 1.4 (and probably other cordova apps) where iOS 10's content security 8 | policy prevents connections via web sockets. 9 | 10 | The new content security policy META element will be: 11 | 12 | ``` 13 | 14 | ``` -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "meteor-ios10-csp-fix", 3 | "version": "0.1.0", 4 | "description": "Fixes the iOS 10 issue with websockets: \"Refused to connect to wss://mydomain.com/sockjs/.../websocket because it appears in neither the connect-src directive nor the default-src directive of the Content Security Policy\"", 5 | "cordova": { 6 | "id": "meteor-ios10-csp-fix", 7 | "platforms": [ 8 | "ios" 9 | ] 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/AppWorkshop/meteor-ios10-csp-fix" 14 | }, 15 | "keywords": [ 16 | "cordova", 17 | "meteor", 18 | "ios", 19 | "ios10", 20 | "csp" 21 | ], 22 | "author": "Mike Cunneen - The App Workshop", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/AppWorkshop/meteor-ios10-csp-fix/issues" 26 | }, 27 | "homepage": "https://github.com/AppWorkshop/meteor-ios10-csp-fix#readme" 28 | } 29 | -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | Meteor 1.4.1 iOS 10 CSP Fix 5 | Fixes the iOS 10 issue with websockets: "Refused to connect to wss://mydomain.com/sockjs/.../websocket because it appears in neither the connect-src directive nor the default-src directive of the Content Security Policy" 6 | MIT 7 | cordova,meteor,ios,ios10,csp 8 | Mike Cunneen - The App Workshop 9 | https://github.com/AppWorkshop/meteor-ios10-csp-fix.git 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /scripts/afterBuild.js: -------------------------------------------------------------------------------- 1 | module.exports = function(context) { 2 | var fs = context.requireCordovaModule('fs'); 3 | var path = context.requireCordovaModule('path'); 4 | var cordova_util = context.requireCordovaModule('cordova-lib/src/cordova/util.js'); 5 | var ConfigParser = context.requireCordovaModule('cordova-common').ConfigParser; 6 | 7 | var projectRoot = context.opts.projectRoot; 8 | 9 | var configXml = cordova_util.projectConfig(projectRoot); 10 | var config = new ConfigParser(configXml); 11 | var projectName = config.name(); 12 | 13 | var wwwPath = path.join(context.opts.projectRoot, 'platforms/ios/www/application/'); 14 | var otherWwwPath = path.join(context.opts.projectRoot, 'www/application/index.html'); 15 | 16 | 17 | var indexHTMLPath = path.join(wwwPath, 'index.html'); 18 | 19 | var oldMetaPattern = ' \`; 25 | 26 | if (oldMetaRegexp.test(data)) { 27 | var newdata = data.replace(oldMetaRegexp, newmeta); 28 | 29 | fs.writeFileSync(indexHTMLPath, newdata); 30 | 31 | console.log(context.opts.plugin.id + ' updating META tag for file ' + indexHTMLPath); 32 | 33 | 34 | if (fs.existsSync(otherWwwPath)) { 35 | data = fs.readFileSync(otherWwwPath, {'encoding': 'utf8'}); 36 | newdata = data.replace(oldMetaRegexp, newmeta); 37 | fs.writeFileSync(otherWwwPath, newdata); 38 | console.log(context.opts.plugin.id + ' updating META tag for file ' + otherWwwPath); 39 | 40 | } 41 | } else { 42 | // no meta tag found. So we'll add one. 43 | // first find the head. 44 | var headpattern = ''; 45 | var headregexp = new RegExp(headpattern, 'i'); 46 | if (headregexp.test(data)) { 47 | // replace with \n 48 | var newdata = data.replace(headregexp, `${headpattern}\n${newmeta}`); 49 | 50 | fs.writeFileSync(indexHTMLPath, newdata); 51 | } 52 | } 53 | } --------------------------------------------------------------------------------