Permalink
Browse files

Added a /launchapp endpoint to locker.js

  • Loading branch information...
1 parent da75456 commit f9d2926334e8262f2188cbe6247a38021aa0f4d2 Simon Murtha-Smith committed Jan 28, 2011
Showing with 41 additions and 1 deletion.
  1. +1 −0 Apps/.gitignore
  2. +4 −1 Ops/Dashboard/dashboard.js
  3. +36 −0 locker.js
View
@@ -0,0 +1 @@
+Fizz/
@@ -34,7 +34,10 @@ function readJSON(res,file) {
app.get('/', function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/html' });
- res.write('<html><head><title>Locker Dashboard</title></head>\n\n<body>');
+ res.write('<html><head><title>Locker Dashboard</title>' +
+ '<script src="http://code.jquery.com/jquery-1.4.4.min.js"></script></head>\n\n<body>');
+ //res.write('launch <a onclick="javascript:$.get(\'http:localhost:1' + rootPort + '/launchapp\', {name:\'Fizz\'})">Fizz!</a>');
+
res.end("</body></html>");
});
View
@@ -109,7 +109,43 @@ function(req, res) {
res.end("{}");
});
+
+locker.get('/launchapp', function(req, res) {
+ var paramsString = req.param('params');
+ console.log('params: ' + params);
+ var params = [];
+ if(paramsString)
+ params = JSON.parse(paramsString);
+ var port = spawnApp(req.param('name'), params);
+ res.writeHead(200, {
+ 'Content-Type': 'text/javascript'
+ });
+ res.end('http://localhost:' + port + '/');
+});
+
locker.listen(lockerPort);
+console.log('locker running at http://localhost:' + lockerPort + '/');
+
+
+//the least intelligent way of avoiding port conflicts
+var appPortCounter = 4000;
+function spawnApp(name, params) {
+ appPortCounter++;
+ var passedParams = ['server.js', appPortCounter];
+ if(params) {
+ for(var i = 0; i < params.length; i++)
+ passedParams.push(params[i]);
+ }
+ app = spawn('node', passedParams, {cwd: 'Apps/' + name});
+ console.log('Spawned app ' + name + ', pid: ' + app.pid);
+ app.stderr.on('data',function (data){
+ console.log('Error in app ' + name + ': '+data);
+ });
+ app.stdout.on('data',function (data){
+ console.log('Contact ' + name + ' at: '+ data);
+ });
+ return appPortCounter;
+}
// scan to load local map of stuff
function mapDir(dir) {

0 comments on commit f9d2926

Please sign in to comment.