Skip to content

Commit

Permalink
Fix new Chrome CORS restriction. Fixes #30
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Mar 10, 2014
1 parent 2587f94 commit 454a3bf
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ JS_COMPILER = uglifyjs

all: js/bundle.min.js

js/bundle.js: js/site.js index.js
js/bundle.js: js/site.js index.js package.json
browserify js/site.js > js/bundle.js

js/bundle.min.js: js/bundle.js
js/bundle.min.js: js/bundle.js package.json
uglifyjs js/bundle.js -c -m > js/bundle.min.js
19 changes: 10 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var restring = require('restring'),
jsonify = require('jsonify'),
http = require('http'),
esprima = require('esprima'),
corslite = require('corslite'),
incrementalEval = require('incremental-eval'),
liveRequire = require('live-require'),
CodeMirror = require('codemirror');
Expand Down Expand Up @@ -37,6 +38,7 @@ function mistakes(__div, clientId) {
}
}),
__res = '';

for (var __i = 0; __i < __r.length; __i++) {
if (__r[__i] !== undefined &&
!(__r[__i] instanceof SyntaxError)) {
Expand All @@ -45,6 +47,7 @@ function mistakes(__div, clientId) {
__res += '\n';
}
}

__result.setValue(__res);
} catch (e) {
__editor.clearGutter('error');
Expand Down Expand Up @@ -141,7 +144,8 @@ function mistakes(__div, clientId) {

function __confirmToken(first) {
if (!localStorage.github_token) return;
xhr({ path: '/user?access_token=' + localStorage.github_token,
xhr({
path: '/user?access_token=' + localStorage.github_token,
host: 'api.github.com',
port: 443,
scheme: 'https'
Expand Down Expand Up @@ -193,14 +197,11 @@ function mistakes(__div, clientId) {
});
} else {
document.body.className = 'loading';
xhr({ path: '/gists/' + id,
host: 'api.github.com',
port: 443,
scheme: 'https'
}, function(res) {
corslite('https://api.github.com/gists/' + id, function(err, res) {
document.body.className = '';
if (err) return;
__showGistButton(id);
var r = jsonify.parse(res);
var r = jsonify.parse(res.responseText);
for (var k in r.files) {
if (isjs(k)) return __content(r.files[k].content);
}
Expand Down Expand Up @@ -259,8 +260,8 @@ function mistakes(__div, clientId) {
readOnly: true
});

__editor.setOption("theme", 'mistakes');
__result.setOption("theme", 'mistakes');
__editor.setOption('theme', 'mistakes');
__result.setOption('theme', 'mistakes');

__s.gist = __gist;
__s.content = __content;
Expand Down
15 changes: 10 additions & 5 deletions js/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function mistakes(__div, clientId) {
}
}),
__res = '';

for (var __i = 0; __i < __r.length; __i++) {
if (__r[__i] !== undefined &&
!(__r[__i] instanceof SyntaxError)) {
Expand All @@ -46,6 +47,7 @@ function mistakes(__div, clientId) {
__res += '\n';
}
}

__result.setValue(__res);
} catch (e) {
__editor.clearGutter('error');
Expand Down Expand Up @@ -142,7 +144,8 @@ function mistakes(__div, clientId) {

function __confirmToken(first) {
if (!localStorage.github_token) return;
xhr({ path: '/user?access_token=' + localStorage.github_token,
xhr({
path: '/user?access_token=' + localStorage.github_token,
host: 'api.github.com',
port: 443,
scheme: 'https'
Expand Down Expand Up @@ -194,10 +197,12 @@ function mistakes(__div, clientId) {
});
} else {
document.body.className = 'loading';
xhr({ path: '/gists/' + id,
xhr({
path: '/gists/' + id,
host: 'api.github.com',
port: 443,
scheme: 'https'
scheme: 'https',
withCredentials: false
}, function(res) {
document.body.className = '';
__showGistButton(id);
Expand Down Expand Up @@ -260,8 +265,8 @@ function mistakes(__div, clientId) {
readOnly: true
});

__editor.setOption("theme", 'mistakes');
__result.setOption("theme", 'mistakes');
__editor.setOption('theme', 'mistakes');
__result.setOption('theme', 'mistakes');

__s.gist = __gist;
__s.content = __content;
Expand Down
8 changes: 4 additions & 4 deletions js/bundle.min.js

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "./node_modules/browservefy/bin/browservefy js/site.js:js/bundle.js 8080 --browserify=./node_modules/browserify/bin/cmd.js -- -d"
"start": "beefy js/site.js:js/bundle.js 8080 -- -d"
},
"repository": {
"type": "git",
Expand All @@ -16,16 +16,17 @@
"readmeFilename": "README.md",
"gitHead": "184b0f281d06ce2f365d89c0dcd4268a7b6223cb",
"dependencies": {
"uglify-js": "~2.2.4",
"uglify-js": "~2.4.12",
"restring": "0.0.0",
"live-require": "0.0.0",
"jsonify": "0.0.0",
"incremental-eval": "0.0.1",
"codemirror": "https://github.com/tmcw/CodeMirror/archive/module-export.tar.gz",
"esprima": "~1.0.4"
"esprima": "~1.0.4",
"corslite": "0.0.5"
},
"devDependencies": {
"browserify": "2.4.3",
"browservefy": "0.0.8"
"browserify": "3.32.1",
"beefy": "~1.1.0"
}
}

0 comments on commit 454a3bf

Please sign in to comment.