Permalink
Browse files

Update rendered root to include custom subdomain

This doesn't account for all generated url's only those in the initial
html and those generated by the client. However this seems to cover
most bases without having to completely refactor the url helper to have
access to the request object.
  • Loading branch information...
aron committed Sep 9, 2012
1 parent ad4a496 commit 0f146f6255608352b0f997ac79c3b0948b2f4380
Showing with 14 additions and 5 deletions.
  1. +12 −4 lib/handlers/bin.js
  2. +2 −1 lib/helpers.js
View
@@ -442,14 +442,22 @@ module.exports = Observable.extend({
helpers = this.helpers,
version = helpers.production ? helpers.set('version') : 'debug',
created = req.flash('checksum') || {},
+ root = helpers.url('', true),
_this = this,
jsbin;
+ // Insert the subdomain if the request has one. Ideally this should be
+ // done by the helper.url() function but it's not currently aware of the
+ // request object.
+ if (req.subdomain) {
+ root = root.replace('://', '://' + req.subdomain + '.');
+ }
+
jsbin = this.jsbin(bin, {
version: version,
token: req.session._csrf,
- root: helpers.set('url full'),
- static: helpers.set('static url'),
+ root: root,
+ static: helpers.urlForStatic(),
settings: config && config.settings,
// If we've pulled a just created bin out of the flash messages object
// then we check to see if the previously created bin is the one we're
@@ -486,8 +494,8 @@ module.exports = Observable.extend({
custom_css: config && config.css,
scripts: helpers.production ? false : scripts,
is_production: helpers.production,
- root: helpers.set('url full'),
- static: helpers.set('static url'),
+ root: root,
+ static: helpers.urlForStatic(),
url: url,
live: req.live,
embed: req.embed,
View
@@ -77,7 +77,8 @@ module.exports.createHelpers = function createHelpers(app) {
path = path.slice(1);
}
- return app.set('static url') + '/' + (path || '');
+ var root = app.set('static url');
+ return path ? root + '/' + (path || '') : root;
}
};
};

0 comments on commit 0f146f6

Please sign in to comment.