From 7db34b296c19d71c8a4388eabb2573ca6f72ba5c Mon Sep 17 00:00:00 2001 From: jkaplon Date: Sun, 21 Feb 2016 09:42:29 -0500 Subject: [PATCH] Git commit triggered by POST request now working. --- server.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/server.js b/server.js index 0426972..b0aaf05 100644 --- a/server.js +++ b/server.js @@ -40,19 +40,29 @@ app.get('/', function(req, res){ app.post('/', function(req, res){ winston.info('POST received'); + var now = Date.now(); // quick/dirty poc is to do a fileSystem.write to create a new file w/contents of req.body! - //var now = Date.now(); //fileSystem.writeFile(__dirname + '/note-data/test-' + now + '.txt', req.body, function(err){ //if (err) { winston.error(err); } //winston.info('new test file written'); //}); // Overwrite allNotes.txt with new contents from client. fileSystem.readFile(notePath, 'utf-8', function(err, data){ - if (err) { winston.error(err); } - fileSystem.writeFile(notePath, req.body, 'utf-8', function(err) { - if (err) { winston.error(err); } - winston.info('new contents from client written to allNotes.txt'); - }); + if (err) { + winston.error(err); + } else { + fileSystem.writeFile(notePath, req.body, 'utf-8', function(err) { + if (err) { winston.error(err); } + winston.info('new contents from client written to allNotes.txt'); + var exec = require('child_process').exec; + var cmd = 'cd note-data && git commit -am "Notes modified via POST request, ' + now + '"'; + winston.info(cmd); + exec(cmd, function(error, stdout, stderr) { + if (error) { winston.error(error); } + winston.info(stdout); + }); + }); + } }); // Stage and commit changes to allNotes.txt. res.status(204).send('POST received');