-
Notifications
You must be signed in to change notification settings - Fork 9
/
post.js
36 lines (28 loc) · 894 Bytes
/
post.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var express = require("express"),
mustacheExpress = require("mustache-express"),
dataChannel = require("./custom_modules/data-channel"),
eventStorage = require("./custom_modules/event-storage"),
bodyParser = require("body-parser"),
app = express();
app.engine('html', mustacheExpress());
app.set('views', './views')
app.set('view engine', 'html');
app.use(express.static("./static"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.get("/api/post-update", function(req, res) {
res.render("postupdate", {});
});
app.put("/api/post-update", function(req, res) {
var json = req.body;
json.timestamp = Date.now();
eventStorage.save(json).then(function(doc) {
dataChannel.publish(JSON.stringify(json));
}, errorHandling);
res.status(204).end();
});
function errorHandling(err) {
throw err;
}
var server = app.listen(8082, function() {
});