Created
March 26, 2018 02:51
-
-
Save drbh/e5d2a1fd4aea188103a009e446362c62 to your computer and use it in GitHub Desktop.
server for iMessage analyzer app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// server.js | |
var express = require("express"); | |
var app = express(); | |
var main = require("./node-main.js") | |
var bodyParser = r equire('body-parser') | |
app.use(bodyParser.json()); // to support JSON-encoded bodies | |
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies | |
extended: true | |
})); | |
var DataGrab = new main.DataGrabber() | |
app.get("/", function(req, res) { | |
console.log('GET - HOME'); | |
res.sendfile('templates/example-page.html') | |
}); | |
app.post("/messages", function(req, res) { | |
console.log('POST - messages'); | |
DataGrab.findGetMessages(req.body.param1).then(function(messages) { | |
Promise.all(messages).then(function(values) { | |
var response = [] | |
for (let msgs of values) { | |
response.push(msgs.rows) | |
} | |
res.send(JSON.stringify(response)); | |
}); | |
}) | |
}); | |
app.get("/last-messages", function(req, res) { | |
console.log('GET - last-messages'); | |
DataGrab.getLastMessages().then(function(messages) { | |
Promise.all(messages.rows).then(function(values) { | |
res.send(JSON.stringify(values)); | |
}); | |
}) | |
}); | |
/* serves all the static files */ | |
app.get("/static/*", function(req, res) { | |
console.log('static ' + req.params['0']); | |
res.sendfile('static/' + req.params['0']) | |
}); | |
var port = process.env.PORT || 5000; | |
app.listen(port, function() { | |
console.log("Listening on " + port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment