-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
36 lines (28 loc) · 905 Bytes
/
server.ts
File metadata and controls
36 lines (28 loc) · 905 Bytes
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
import express from 'express';
import { callAPI } from './COvin';
import { insertObject } from './dbUtil';
let path = require('path');
let fs = require('fs');
let bodyParser = require('body-parser');
let app = express();
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname,'..', 'index.html'));
});
app.get('/covid19logo', function (req, res) {
let img = fs.readFileSync(path.join(__dirname,'..', "covid19logo.jpg"));
res.writeHead(200, {'Content-Type': 'image/jpg' });
res.end(img, 'binary');
});
app.post('/user-details', function (req, res) {
let user = req.body;
console.log(JSON.stringify(user));
insertObject(user.email, user.district).then((data) => res.send(data));
});
app.listen(3000, function () {
console.log('Listening on port 3000...')
setInterval(callAPI, 30000);
})