-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
50 lines (42 loc) · 1 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
const express = require('express');
const app = express();
const server = require('http').Server(app);
const io = require('socket.io')(server);
const stream = require('./src/ws/stream');
const path = require('path');
const favicon = require('serve-favicon');
const Datastore = require('nedb');
const port = process.env.PORT || 8000;
const dataBase = new Datastore('datas/my-meetings.db');
dataBase.loadDatabase();
app.use(favicon(path.join('src', 'favicon.ico')));
app.use('/assets', express.static(path.join('src', 'assets')));
app.use(express.static('src'));
app.use(
express.json({
limit: '2mb',
})
);
app.get('/api', (req, res) => {
dataBase.find({}, (err, data) => {
if (err) {
res.end();
return;
} else {
res.json(data);
}
});
});
server.listen(port);
app.post('/api', (request, respone) => {
dataBase.insert(request.body);
});
app.post('/pi', (req, res) => {
dataBase.remove(req.body, (err) => {
if (err) {
res.end();
return;
}
});
});
io.of('/stream').on('connection', stream);