-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
95 lines (94 loc) · 3.55 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
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
91
92
93
94
95
var express = require('express'),
x = require('x-ray')(),
moment = require('moment'),
q = require('q'),
articlesController = require('./server/controllers/articles-server-controller'),
retriever = require('./lib/retriever'),
timeout = require('./lib/timeouts'),
compression = require('compression'),
serveStatic = require('serve-static'),
bodyParser = require('body-parser'),
morgan = require('morgan'),
session = require('express-session'),
app = express();
// initializations
app.use(morgan('dev'));
app.use(session({
secret: "monobelle",
resave: false,
saveUninitialized: true,
cookie: {secure: true}
}));
app.set('views',__dirname + '/client/views');
app.set('view engine','ejs');
app.use('/fonts', express.static(__dirname + '/public/fonts'));
app.use('/css', express.static(__dirname + '/public/css'));
app.use('/js', express.static(__dirname + '/public/js'));
app.use('/img', express.static(__dirname + '/public/img'));
app.use('/client/js', express.static(__dirname + '/client/js'));
app.use('/server/js', express.static(__dirname + '/server/js'));
app.use(express.static(__dirname + '/node_modules/bootstrap/dist'));
app.use(bodyParser.json());
app.use(compression());
app.use(serveStatic('/public/*/*'));
app.use(serveStatic('/css/*.*'));
app.use(serveStatic('/js/*.*'));
app.use(serveStatic('/img/*.*'));
app.use(serveStatic('/client/js/*.*'));
app.use(serveStatic('/server/js/*.*'));
// // routes: google analytics
// var gaRouter = express.Router();
// gaRouter.get('/oauthcallback?:code',(req,res)=>{
// var code = req.params.code;
// console.log('req.params',req.params);
// // queryData(ga);
// console.log('authentic');
// res.render('png');
// })
// gaRouter.get('/test', (req,res)=>{
// console.log('/test route accessed.')
// // queryData(ga);
// res.render('search')
// })
// app.use('/ga',gaRouter);
// http requests
app.post('/', function(req, res) {
res.redirect('/populate');
});
app.get('/', function(req, res) {
res.render('articles');
});
app.get('/write/:country', function(req, res) {
var country = req.params.country;
retriever.getArticles(country,8,0);
res.redirect('/page/'+country);
});
// api call to get stories
app.get('/articles/:country', articlesController.listArticles);
app.get('/page/:country', function(req, res){res.render(req.params.country)});
// uri call to get top 5 stories
app.get('/top/:country', articlesController.top5);
app.get('/top-5/:country', function(req, res) {res.render(req.params.country + '-top-5')});
// api call to export stories
app.get('/export/:country/:startDate', articlesController.exportArticles);
app.get('/export/:country', articlesController.exportArticles);
app.get('/search', (req, res) => {res.render('search')});
app.get('/query/', articlesController.queryArticles);
app.get('/api/query/', (req,res) => {res.render('query')});
// api call to populate stories
app.get('/populate', (req, res) => {res.render('populate')});
app.get('/populate/content/', function(req, res) {
var country = req.query.country.toLowerCase(), start = Number.parseInt(req.query.start), stop = Number.parseInt(req.query.stop);
retriever.getArticles(country,start,stop);
res.redirect('/page/'+country);
});
app.get('/populate/auto/', (req, res) => {
var start = Number.parseInt(req.query.start),
stop = Number.parseInt(req.query.counter),
country = req.query.country.toLowerCase();
timeout.activateRetrieval(country,start,stop);
res.redirect('/page/'+country);
});
app.set('port', (process.env.PORT || 3000));
app.listen(app.get('port'), function() { console.log('app started at port ' + app.get('port')); });
// module.exports = express;