-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
90 lines (73 loc) · 2.07 KB
/
server.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const express = require('express');
const cors = require('cors');
const stock = require('./controllers/stock');
const fintwit = require('./controllers/fintwit');
const misc = require('./controllers/misc');
const apicache = require('apicache');
const app = express();
app.use(express.json());
app.use(cors());
// DATABASE
// const db = knex({
// client: 'pg',
// connection: {
// connectionString: process.env.DATABASE_URL,
// ssl: {
// rejectUnauthorized: false,
// },
// },
// });
// MIDDLEWARE
let cache = apicache.middleware;
const onlyStatus200 = (req, res) => res.statusCode === 200;
const cacheSuccesses15 = cache('15 minutes', onlyStatus200);
const cacheSuccesses60 = cache('60 minutes', onlyStatus200);
// HOME
app.get('/', (req, res) => {
res.json('Launching Application...');
});
// SEARCH
app.get('/search/:ticker', (req, res) => {
stock.getCompanyOverview(req, res);
});
app.get('/quote/:ticker', (req, res) => {
stock.getQuote(req, res);
});
// CHARTS
app.get('/chart/intraday/:ticker', cacheSuccesses15, (req, res) => {
stock.getIntradayData(req, res);
});
app.get('/chart/daily/:ticker', cacheSuccesses15, (req, res) => {
stock.getDailyData(req, res);
});
// NEWS
app.get('/news/:ticker?', cacheSuccesses15, (req, res) => {
stock.getNews(req, res);
});
// TRENDING
app.get('/trending/:fintwit', cacheSuccesses60, (req, res) => {
fintwit.getTrending(req, res);
});
// MARKET MOVERS
app.get('/mostactives', cacheSuccesses60, (req, res) => {
stock.getMostActive(req, res);
});
app.get('/smallcaps', cacheSuccesses60, (req, res) => {
stock.getSmallCapGainer(req, res);
});
app.get('/gainers', cacheSuccesses60, (req, res) => {
stock.getDayGainers(req, res);
});
app.get('/losers', cacheSuccesses60, (req, res) => {
stock.getDayLosers(req, res);
});
// MISC
app.get('/insiders', cacheSuccesses60, (req, res) => {
misc.getInsiders(req, res);
});
app.get('/latestnews', cacheSuccesses60, (req, res) => {
misc.getLatestNews(req, res);
});
let port = process.env.PORT || 3000;
app.listen(port);
console.log('RESTful API server started on: ' + port);