Skip to content

Commit

Permalink
Merge pull request AVGP#4 from stealthdave/master
Browse files Browse the repository at this point in the history
Add HTTPS support to Cloud9Hub
  • Loading branch information
AVGP committed May 5, 2014
2 parents 37b8b79 + f097051 commit c9b8bf2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
6 changes: 6 additions & 0 deletions config.js.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ exports.PERMITTED_USERS = false;
// This restricts signup to the users alice and bob:
//exports.PERMITTED_USERS = ['alice', 'bob'];
exports.BASE_URL = 'http://localhost';
// Add SSL Certificates to use Cloud9Hub over SSL
// (Cloud9 Workspaces will still be unsecured standard HTTP)
//exports.SSL = {
// key: "/path/to/ssl.key",
// cert: "/path/to/ssl.pem"
//};
8 changes: 5 additions & 3 deletions public/javascripts/workspace/workspaceController.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ var WorkspaceCtrl = function($scope, $http, $timeout) {

$scope.runWorkspace = function(name) {
console.log(name);
$http.get('/workspace/' + name).success(function(data) {
var authUser = Math.random().toString(36).substring(2),
authPassword = Math.random().toString(36).substring(2);
$http.get('/workspace/' + name + '?username=' + authUser + '&password=' + authPassword).success(function(data) {
console.log(data);
$timeout(function() {
$scope.currentWorkspace.url = data.url;
$scope.currentWorkspace.url = data.url.replace(/^https:\/\//,'http://' + authUser + ':' + authPassword + '@');
_sendKeepAlive();
}, 2000);

Expand All @@ -57,4 +59,4 @@ var WorkspaceCtrl = function($scope, $http, $timeout) {
});
$scope.currentWorkspace.name = name;
}
}
}
18 changes: 14 additions & 4 deletions routes/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ var createWorkspace = function(params, req, res) {

var createWorkspaceKillTimeout = function(workspaceProcess, workspaceName) {
var timeout = setTimeout(function() {
process.kill(-workspaceProcess.pid, 'SIGTERM');
console.info("Killed workspace " + workspaceName);
try {
process.kill(-workspaceProcess.pid, 'SIGTERM');
console.info("Killed workspace " + workspaceName);
} catch (e) {
console.error("Workspace expired but not found: " + workspaceName);
}
}, 900000); //Workspaces have a lifetime of 15 minutes

return timeout;
Expand Down Expand Up @@ -104,7 +108,13 @@ exports.destroy = function(req, res) {

console.log("Starting " + __dirname + '/../../c9/bin/cloud9.sh for workspace ' + workspaceName + " on port " + req.nextFreePort);

var workspace = spawn(__dirname + '/../../c9/bin/cloud9.sh', ['-w', __dirname + '/../workspaces/' + req.user + '/' + workspaceName, '-l', '0.0.0.0', '-p', req.nextFreePort], {detached: true});
var workspace = spawn(__dirname + '/../../c9/bin/cloud9.sh', [
'-w', __dirname + '/../workspaces/' + req.user + '/' + workspaceName,
'-l', '0.0.0.0',
'-p', req.nextFreePort,
'--username', req.query['username'],
'--password', req.query['password']
], {detached: true});
workspace.stderr.on('data', function (data) {
console.log('stdERR: ' + data);
});
Expand All @@ -126,4 +136,4 @@ exports.destroy = function(req, res) {
clearTimeout(workspace.killTimeout);
workspace.killTimeout = createWorkspaceKillTimeout(workspace.process, workspace.name);
res.send();
}
}
16 changes: 15 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var express = require('express')
, fs = require('fs')
, path = require('path')
, http = require('http')
, https = require('https')
, path = require('path')
, passport = require('passport')
, GithubStrategy = require('passport-github').Strategy;
Expand Down Expand Up @@ -99,7 +100,20 @@ app.get('/workspace/:name', ensureAuthenticated, workspace.run);
app.post('/workspace/:name/keepalive', ensureAuthenticated, workspace.keepAlive);
app.delete('/workspace/:name', ensureAuthenticated, workspace.destroy);

http.createServer(app).listen(app.get('port'), function(){
var server;

if (config.SSL && config.SSL.key && config.SSL.cert) {
var sslOpts = {
key: fs.readFileSync(config.SSL.key),
cert: fs.readFileSync(config.SSL.cert)
};

server = https.createServer(sslOpts, app);
} else {
server = http.createServer(app);
}

server.listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});

Expand Down

0 comments on commit c9b8bf2

Please sign in to comment.