-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (49 loc) · 1.67 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');
const connectDatabase = require('./config/database')
const sourceData = require('./config/sourceData')
const dotenv = require('dotenv');
const {govRouter, presiRouter, presiStateRouter, presiCandidateRouter, userRouter, presi2015Router, presiCandidate2015Router} = require('./routers/index');
//extra security packages
const helmet = require('helmet');
const cors = require('cors');
const xss = require('xss-clean');
//const rateLimiter = require('express-rate-limit');
const app = express()
app.set('trust proxy', 1);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(helmet());
app.use(cors());
app.use(xss());
/*app.use(rateLimiter({
windowMs: 60 * 1000,
max: 60, // limit each IP to 60 requests per windowMs
}));
*/
//connecting to Database
connectDatabase();
//connecting to env file
dotenv.config();
//connecting to extracting delection data from different source
//sourceData();
// admin users
app.use('/api/users', userRouter);
//presidential election
app.use('/api/presidential', presiRouter);
app.use('/api/2019/presidential-candidates', presiCandidateRouter);
app.use('/api/2015/presidential-candidates', presiCandidate2015Router);
app.use('/api/2019/presidential/stateinfo', presiStateRouter);
//app.use('/api/governors', govRouter);
app.get('/', (req, res) => {
res.send(`Nigeria Election API`);
//res.send(sourceData());
});
app.get('/news', async (req, res) => {
const {url, contentName} = req.query;
const news = await sourceData(url, contentName);
res.send(news);
});
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log(`Serve at http://localhost:${port}`);
});