Permalink
Browse files

Allow JSBIN_URL to change BOTH the port and the url port - important …

…for the executable
  • Loading branch information...
1 parent 0daaf30 commit e347346dc07b21f028734b70784f189940592407 @remy remy committed Jul 27, 2012
Showing with 15 additions and 0 deletions.
  1. +15 −0 lib/app.js
View
@@ -10,6 +10,7 @@ var nodemailer = require('nodemailer'),
routes = require('./routes'),
handlers = require('./handlers'),
middleware = require('./middleware'),
+ url = require('url'),
flattened;
app.store = store;
@@ -49,6 +50,18 @@ if (!process.env.TZ && options.timezone) {
(function () {
var port = process.env.PORT;
+ // if we're running from the bin/jsbin file, then we modify
+ // both the listen port AND the options.url
+ if (process.env.JSBIN_PORT) {
+ if (options.url.host.indexOf(':') === -1) {
+ options.url.host += ':' + process.env.JSBIN_PORT;
+ } else {
+ options.url.host = options.url.host.replace(/\:\d+$/, function () {
+ return ':' + process.env.JSBIN_PORT;
+ });
+ }
+ }
+
if (!port) {
options.url.host.replace(/\:(\d+)$/, function (m, p) {
if (p.length) {
@@ -61,6 +74,8 @@ if (!process.env.TZ && options.timezone) {
port = 80;
}
+ // NOTE: this is *only* used for running the server.listen()
+ // it's not used in the urls to access assets, etc.
options.port = port;
})();

0 comments on commit e347346

Please sign in to comment.