Skip to content

Commit

Permalink
refactor: revert appcache stuff
Browse files Browse the repository at this point in the history
Not ready and very unstable
  • Loading branch information
remy committed May 10, 2017
1 parent 9bf4af0 commit 3bd9a97
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 61 deletions.
2 changes: 0 additions & 2 deletions build/populate.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ var getBin = function (ownerBin, cb) {
// Populate the summary field of the owner table

var populateBin = function (ownerBin, done) {
console.log("%d", ownerBin.id);

getBin(ownerBin, function (err, sandboxBin) {
if (err) return done(err);
if (!sandboxBin) return done();
Expand Down
2 changes: 1 addition & 1 deletion emails/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<p style="margin: 20px 0;">Thanks for signing up. To get familiar with JS Bin, check out our <a style="text-decoration: underline;" href="https://jsbin.com/help?utm_medium=email">help</a> and follow <a style="text-decoration: underline;" href="https://twitter.com/js_bin">@js_bin</a> on Twitter.</p>
{{#if code}}
<p style="margin: 20px 0;">As an exclusive gift, I'm offering you a month of free Pro – <span style="font-weight: bold">total saving of over&nbsp;$100(!)</span> when you subscribe to a yearly pro account with the special code: <a style="font-weight: bold;text-decoration: underline;" href="https://jsbin.com/upgrade?coupon={{code}}&amp;utm_source=welcome-email&amp;utm_medium=email&amp;utm_campaign=welcome-email-discount
">{{code}}</a> (valid for a month from today).</p>
">{{code}}</a> (valid until the end of *this* month).</p>
{{else}}
<p style="margin: 20px 0;">If you want to power-up your JS Bin usage, you can <a href="https://jsbin.com/upgrade?coupon={{code}}&amp;utm_source=welcome-email&amp;utm_medium=email&amp;utm_campaign=welcome-email">upgrade your account to Pro today</a>, and you'll have access to unlimited private bins, asset uploading, experimental features and more.</p>
{{/if}}
Expand Down
4 changes: 1 addition & 3 deletions lib/dropbox/binfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ var binfile = (function () {

closingScriptTag.lastIndex = 0;

console.log(js);
output = insertCode(output, js, '%code%', '</body>', function () {
// var type = jsbin.panels.panels.javascript.type ? ' type="text/' + jsbin.panels.panels.javascript.type + '"' : '';
var type = '';
Expand All @@ -76,9 +75,8 @@ var binfile = (function () {
return '<style id="jsbin-css-output" class="jsbin-css">\n' + css + '\n</style>\n';
});

console.log(output);
if (data.source) {

}
// TODO this would be a good point to trigger a filter on the completed HTML
// that *doesn't* yet contain the source data
Expand Down
1 change: 0 additions & 1 deletion lib/handlers/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ var errors = require('../errors');
var Observable = utils.Observable;
var passport = require('passport');
var clone = require('clone');
var Promise = require('promise');
const denodeify = require('denodeify');

module.exports = Observable.extend({
Expand Down
1 change: 0 additions & 1 deletion lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ var middleware = module.exports = {
if (skipCSRF) {
next();
} else {
console.log(req.signedCookies);
return csrf(req, res, next);
}
}
Expand Down
46 changes: 23 additions & 23 deletions lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,18 @@ function mountRouter(expressApp) {
// /about doesn't get hit in production - it goes via nginx to our learn repo
app.get('/about', redirect('http://jsbin.com/about'));

app.get('/manifest.appcache', (req, res) => {
var statik = sandbox.helpers.urlForStatic(undefined, true);
res.set('content-type', 'text/cache-manifest');
res.set('Cache-Control', 'public, max-age=0'); // don't cache
console.log(req.session);
res.render('manifest-appcache', {
version: req.app.settings.version,
root: statik,
open: req.session.open,
layout: false,
});
});
// NOTE another day perhaps…
// app.get('/manifest.appcache', (req, res) => {
// var statik = sandbox.helpers.urlForStatic(undefined, true);
// res.set('content-type', 'text/cache-manifest');
// res.set('Cache-Control', 'public, max-age=0'); // don't cache
// res.render('manifest-appcache', {
// version: req.app.settings.version,
// root: statik,
// open: req.session.open,
// layout: false,
// });
// });

app.get('/manifest.json', function (req, res) {
var statik = sandbox.helpers.urlForStatic(undefined, true);
Expand Down Expand Up @@ -321,14 +321,14 @@ function mountRouter(expressApp) {
app.get(['/-', '/null'], features.route('sandbox'), tag('sandbox'), binHandler.getDefault, binHandler.render);

// Runner - if in production, let nginx pick up the runner
// if (expressApp.locals.is_production) {
// expressApp.render('runner', {
// scripts: scripts.runner,
// 'static': sandbox.helpers.urlForStatic(undefined, true),
// }, function (error, html) {
// fs.writeFile(__dirname + '/../public/runner.html', html, () => {});
// });
// }
if (expressApp.locals.is_production) {
expressApp.render('runner', {
scripts: scripts.runner,
'static': sandbox.helpers.urlForStatic(undefined, true),
}, function (error, html) {
fs.writeFile(__dirname + '/../public/runner.html', html, () => {});
});
}

app.get('/runner', function (req, res) {
req.session.open = !!req.query.pro;
Expand All @@ -338,9 +338,9 @@ function mountRouter(expressApp) {
});
});

app.get('/runner-inner', function (req, res) {
res.send('<html manifest="/manifest.appcache"></html>');
});
// app.get('/runner-inner', function (req, res) {
// res.send('<html manifest="/manifest.appcache"></html>');
// });

app.post('/processor', features.route('processors'), function (req, res) {
processors.run(req.body.language, req.body).then(function (data) {
Expand Down
54 changes: 29 additions & 25 deletions public/js/runner/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,54 @@ var sandbox = (function () {
*/
sandbox.create = function () {
var iframe = document.createElement('iframe');
iframe.src = window.location.origin + '/runner-inner';
// iframe.src = window.location.origin + '/runner-inner';
iframe.setAttribute('sandbox', 'allow-modals allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts');
iframe.setAttribute('frameBorder', '0');
iframe.setAttribute('name', 'JS Bin Output ');
iframe.id = sandbox.guid++;
sandbox.active = iframe;
// sandbox.active = iframe;
return iframe;
};

/**
* Add a new iframe to the page and wait until it has loaded to call the
* requester back. Also wait until the new iframe has loaded before removing
* the old one.
*/
/**
* Add a new iframe to the page and wait until it has loaded to call the
* requester back. Also wait until the new iframe has loaded before removing
* the old one.
*/
sandbox.use = function (iframe, done) {
if (!sandbox.target) throw new Error('Sandbox has no target element.');
// sandbox.old = sandbox.active;
// sandbox.active = iframe;
if (!sandbox.target) {
throw new Error('Sandbox has no target element.');
}
sandbox.old = sandbox.active;
sandbox.saveState(sandbox.old);
sandbox.active = iframe;
prependChild(sandbox.target, iframe);

// setTimeout allows the iframe to be rendered before other code runs,
// allowing us access to the calculated properties like innerWidth.
setTimeout(function () {
// call the code that renders the iframe source
// if (done) done();
sandbox.active.contentWindow.addEventListener('load', function () {
console.log('IFRAME LOADED');
if (done) done();


// remove *all* the iframes, baring the active one
var iframes = sandbox.target.getElementsByTagName('iframe'),
length = iframes.length,
i = 0,
id = sandbox.active.id,
iframe;

for (; iframe = iframes[i], i < length; i++) {
if (iframe.id !== id) {
iframe.parentNode.removeChild(iframe);
length--;
}
if (done) {
done();
}

// remove *all* the iframes, baring the active one
var iframes = sandbox.target.getElementsByTagName('iframe');
var length = iframes.length;
var i = 0;
var id = sandbox.active.id;
var iframe;

for (; iframe = iframes[i], i < length; i++) {
if (iframe.id !== id) {
iframe.parentNode.removeChild(iframe);
length--;
}
});
}
}, 0);
};

Expand Down
1 change: 0 additions & 1 deletion test/unit/lib/email.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var test = require('tap-only');
global.Promise = require('promise'); // expose
var root = __dirname + '/../../..';
var emailSender = require(root + '/lib/email');

Expand Down
1 change: 0 additions & 1 deletion test/unit/lib/stripe/customer-subscription-created.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var test = require('tap-only');
global.Promise = require('promise'); // expose
var root = __dirname + '/../../../..';
var event = require(root + '/test/fixtures/customer.subscription.created.json').data.object;
var user = require(root + '/test/fixtures/customer.json');
Expand Down
2 changes: 1 addition & 1 deletion views/runner-wrapper.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<html manifest="/manifest.appcache">
<html>
<script>console.log('wrapper ready')</script>
</html>
3 changes: 1 addition & 2 deletions views/runner.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html manifest="/manifest.appcache">
<html>
<meta charset=utf-8>
<title>JS Bin Runner</title>

Expand All @@ -20,7 +20,6 @@
width: 100%;
}
</style>
<iframe src="{{root}}/runner-inner"></iframe>
<div id="sandbox-wrapper"></div>
{{#if settings.is_production}}
<script>
Expand Down

0 comments on commit 3bd9a97

Please sign in to comment.