-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
58 lines (47 loc) · 1.69 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const express = require('express');
var cors = require('cors');
logger = require('./lib/logger');
const quotes = require('./src/quotes');
const config = require('./config.json');
const app = express();
const PORT = process.env.PORT || config.port;
app.use(cors({ origin: '*' }));
app.post('/writeQuotes', (req, res) => {
if (!req.query.exchange) {
console.log(`'exchange' parameter missing.`)
logger.info(`'exchange' parameter missing.`)
}
else {
console.log('/writeQuotes Called.')
logger.info('/writeQuotes Called.')
quotes.writeQuotes(req.query.exchange).then(response => res.send(response));
}
});
app.get('/getQuote', (req, res) => {
if (!req.query.exchange) {
console.log(`'exchange' parameter missing.`)
logger.info(`'exchange' parameter missing.`)
return (`'exchange' parameter missing.`)
}
else if (!req.query.symbol) {
console.log(`'symbol' parameter missing.`)
logger.info(`'symbol' parameter missing.`)
return (`'symbol' parameter missing.`)
}
else {
console.log('/getQuote Called.')
logger.info('/getQuote Called.')
quotes.getQuote({ symbol: req.query.symbol }, req.query.exchange, 0)
.then(quote => res.json(quote))
.catch(err => {
res.status(404);
logger.error(`Couldn't get quote for ${req.query.symbol}`)
res.send(`Couldn't get quote for ${req.query.symbol}`);
});
}
});
let server = app.listen(PORT, () => {
console.log(`Example app listening on port ${PORT}`);
logger.info(`Example app listening on port ${PORT}`);
});
server.timeout = config.timeout * 2;