-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (30 loc) · 979 Bytes
/
server.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
37
38
39
'use strict';
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var influx = require('influx');
var Config = require('./config.json');
// influx
var client = influx(Object.assign({}, Config.influx));
// bodyParser for post requests
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
var port = process.env.PORT || 8080;
var router = express.Router();
// test route
router.get('/', function(req, res) {
res.json({ message: 'hooray! welcome to our api!' });
});
router.route('/printer/status')
.get(function(req, res) {
var query = 'select last(value) from "status" order asc';
client.query(query, function (err, results) {
if (err)
res.send(err);
res.json([{'status':results[0].points[0][1]}]);
});
});
// all of our routes will be prefixed with /api
app.use('/api', router);
app.listen(port);
console.log('Magic happens on port ' + port);