-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (53 loc) · 1.65 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
59
60
const express = require('express');
const app = express();
const azureUtilities = require('./utilities/microsoftAzure.js');
const newsUtilities = require('./utilities/newsAPI.js');
const parseNewsArticles = require('./utilities/parseNewsData.js');
app.use(express.static('./client/dist'));
app.get('/publishers', (client_req, client_res) => {
newsUtilities.getNewsPublications((data) => {
client_res.send(data);
});
});
app.get('/analysis', (client_req, client_res) => {
const query = client_req.url.substring(
client_req.url.indexOf('?') + 1,
client_req.url.length
);
newsUtilities.getNewsArticles(query, (data) => {
let news_data = JSON.parse(data);
azureUtilities.getAnalysis(parseNewsArticles(news_data), (azure_data) => {
let package = {
articles: news_data.articles,
analytics: azure_data
};
client_res.send(package);
});
});
});
app.get('/avgTopByPublisher', (client_req, client_res) => {
const pub = client_req.url.substring(
client_req.url.indexOf('?') + 1,
client_req.url.length
);
newsUtilities.getTopHeadlinesForPublication(pub, (data) => {
let news_data = JSON.parse(data);
if (news_data.articles.length < 1) {
let package = {
articles: news_data.articles,
analytics: { documents: [] }
};
client_res.send(package);
return;
}
azureUtilities.getAnalysis(parseNewsArticles(news_data), (azure_data) => {
let package = {
articles: news_data.articles,
analytics: azure_data
};
client_res.send(package);
});
});
});
const port = 3001;
app.listen(port, console.log('listening on port:', port));