Skip to content

Commit 2aa0483

Browse files
committed
First commit
0 parents  commit 2aa0483

File tree

343 files changed

+41945
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

343 files changed

+41945
-0
lines changed

.idea/scopes/scope_settings.xml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

+461
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: node app.js

app.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
/**
4+
*
5+
* Main application
6+
*/
7+
var express = require("express"),
8+
morgan = require("morgan"),
9+
errorHandler = require('errorhandler'),
10+
bodyParser = require('body-parser'),
11+
http = require('http'),
12+
app = express();
13+
14+
// Some uses
15+
app.use(morgan('dev'));
16+
app.use(bodyParser.json());
17+
18+
// Require the master (cluster) app
19+
require('./master')(app);
20+
21+
// development only
22+
if (app.get('env') == 'development') {
23+
app.use(errorHandler());
24+
}
25+
else { // production error handling
26+
app.use(function(err, req, res, next){
27+
console.error(err.stack);
28+
res.send(500, 'Something broke!');
29+
});
30+
}
31+
32+
33+
var port = Number(process.env.PORT || 5000);
34+
35+
http.createServer(app).listen(port, function(){
36+
console.log('Express server listening on port ' + port);
37+
});

master.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
3+
module.exports = function(app) {
4+
var cluster = require('cluster');
5+
6+
cluster.setupMaster({
7+
exec : "worker.js", // run this script when we fork ourselves
8+
args : process.argv.slice(2),
9+
silent : false
10+
});
11+
12+
// Routing
13+
app.get('/', function(req, res) {
14+
res.send(401, 'Unauthorized');
15+
});
16+
17+
app.post('/js', function(req, res) {
18+
// Sanitize input first
19+
var command = req.body.command;
20+
21+
if (typeof command === 'undefined') {
22+
res.send(400);
23+
return;
24+
}
25+
26+
//This will be fired when the forked process becomes online
27+
cluster.on("online", function(worker) {
28+
var timer = 0;
29+
30+
worker.on("message", function (message) {
31+
clearTimeout(timer);
32+
console.log(message);
33+
worker.destroy(); // destroy the spun worker
34+
res.send({'text': message});
35+
});
36+
37+
// handle long running processes here (5 seconds tops)
38+
timer = setTimeout(function() {
39+
worker.destroy();
40+
console.log("worker execution expired");
41+
res.send(400, 'Invalid command supplied');
42+
}, 5000);
43+
worker.send(command); // Send the expression to run from the worker
44+
});
45+
46+
cluster.fork(); // fork one process so if for some reason the executed code hangs it doesn't crash the server
47+
});
48+
};

node_modules/body-parser/.npmignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/body-parser/HISTORY.md

+90
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/body-parser/README.md

+144
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)