-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (34 loc) · 1.4 KB
/
index.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
const deviceManager = require('./controllers/device-manager.js');
const serviceOrchestrator = require('./controllers/service-orchestrator.js');
const mongoose = require('mongoose');
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
mongoose.connect('mongodb://localhost/iot-platform');
let db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error'));
db.once('open', () => {
console.log('Connection is established to the database');
});
deviceManager.start().then(() => {
serviceOrchestrator.start();
});
const deviceRouter = require('./routes/device-router.js');
app.use('/device', deviceRouter);
const serviceRouter = require('./routes/service-router.js');
app.use('/service', serviceRouter);
const monitorRouter = require('./routes/monitor-route.js');
app.use('/monitor', monitorRouter);
app.get('/', (req, res) => res.send('Hello World!'));
app.listen(3000, () => console.log('Listening on port 3000!'));