flappy-es/web/server.js

32 lines
835 B
JavaScript
Raw Normal View History

2017-04-04 18:04:18 +00:00
var express = require('express'),
app = express(),
server = require('http').Server(app),
io = require('socket.io')(server)
exec = require('child_process').exec
compression = require('compression')
2017-04-05 16:37:20 +00:00
path = require('path'),
router = express.Router();
2017-04-04 18:04:18 +00:00
server.listen(8088);
2017-04-05 16:37:20 +00:00
router.use(express.static(__dirname + '/static'))
router.use(compression())
router.use('/assets/', express.static(__dirname + '/../assets/'))
2017-04-04 18:04:18 +00:00
var record = path.resolve(__dirname, '../record.py');
2017-04-05 16:37:20 +00:00
router.get('/play', function(request, response) {
2017-04-04 18:04:18 +00:00
var child = exec('python3 ' + record, { maxBuffer: 1024 * 5000 }, function(err, out, stderr) {
if (err || stderr) {
console.log(err || stderr)
response.send(err || stderr);
return;
}
});
child.stdout.pipe(response);
});
2017-04-05 16:37:20 +00:00
app.use('/flappy-bird', router);