From 0491df321d613c0385eec2774c835c5b765adacf Mon Sep 17 00:00:00 2001 From: jkaplon Date: Tue, 16 Jun 2015 22:52:06 -0400 Subject: [PATCH] initial version capable of receiving POST data from Particle Core --- Dockerfile | 2 ++ index.html | 8 ++++++++ package.json | 9 +++++++++ server.js | 25 +++++++++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 Dockerfile create mode 100644 index.html create mode 100644 package.json create mode 100644 server.js diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..13f6eb5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,2 @@ +FROM node:0.12.4-onbuild +EXPOSE 3000 diff --git a/index.html b/index.html new file mode 100644 index 0000000..b808d96 --- /dev/null +++ b/index.html @@ -0,0 +1,8 @@ + + + + + +

Test page for Alert Monitor app:

+ + diff --git a/package.json b/package.json new file mode 100644 index 0000000..140c61d --- /dev/null +++ b/package.json @@ -0,0 +1,9 @@ +{ + "name": "alertmon", + "version": "0.0.1", + "dependencies": { + "body-parser": "^1.12.4", + "express": "^4.12.4" + }, + "scripts": { "start": "node server.js" } +} diff --git a/server.js b/server.js new file mode 100644 index 0000000..8b54ff1 --- /dev/null +++ b/server.js @@ -0,0 +1,25 @@ +var express = require("express"); +var fs = require("fs"); +var bodyParser = require("body-parser"); +var app = express(); +var logfile = fs.createWriteStream('./log.log', {flags: 'a'}); + +app.use(bodyParser.json()); + +app.get('/', function(req, res){ + //res.sendFile("/usr/src/app/index.html"); + fs.createReadStream('./log.log').pipe(res); + console.log("got a GET request..."); +}); + +app.post('/', function(req, res){ + var postEvent = req.body.postEvent; + var source = req.body.source; + console.log("Post event = "+postEvent+", source is "+source); + console.log(req.body); + //res.send(JSON.stringify(req.body, null, 4)); +}); + +app.listen(3000, function() { + console.log("Started on PORT 3000"); +})