-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
67 lines (51 loc) · 1.76 KB
/
app.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'use strict';
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var users = require('./lib/users');
var sensors = require('./lib/sensors');
var projects = require('./lib/projects');
var config = require('./config.js');
var app = express();
// app.use(express.static('./sensorweb-frontend'));
app.use(bodyParser.urlencoded({ extended: false }));
mongoose.connect('mongodb://localhost/test');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
app.route('/').get(function(req, res, next) {
res.jsonp({
version: config.version,
description: config.description,
status: 'good'
});
});
// Get all sensors API is only for testing.
app.route('/sensors')
.get(sensors.getSensors)
app.route('/sensors/:sensorId')
.get(sensors.getSensors)
.put(sensors.editSensor)
.delete(sensors.deleteSensor);
app.route('/sensors/:sensorId/data')
.get(sensors.getSensorData)
.post(sensors.addSensorData);
app.route('/projects/:userId/:projectName')
.get(projects.getProjects);
app.route('/projects/:userId/:projectName/sensors')
.get(sensors.getSensors)
.post(sensors.addSensor);
app.route('/projects/:userId/:projectName/contributors')
.get(projects.getContributors);
app.route('/users')
.get(users.getUserData) // Get user data by email: `/users?email=[USER_EMAIL]`.
.post(users.addUser);
app.route('/users/:userId')
.get(users.getUserData);
app.route('/users/:userId/sensors')
.get(sensors.getSensors);
app.route('/users/:userId/projects')
.get(projects.getProjects);
});
app.listen(config.express.port);
console.log('Listening on port ' + config.express.port);