-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.js
26 lines (25 loc) · 933 Bytes
/
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
const express = require('express');
const facts = require('./facts');
const helpers = require('./helpers');
const app = express();
app.get('/', function(request, response) {
response.send({
'author' : 'Sameer Kumar',
'author_url' : 'https://www.sameerkumar.website',
'base_url' : 'https://useless-facts.sameerkumar.website',
'project_name' : 'Useless Facts API',
'project_url' : 'https://github.com/sameerkumar18/useless-facts-api'
})
});
app.get('/api', function(request, response) {
let count = parseInt(request.query.count) || 1;
let useless_facts = facts.useless_facts;
if(count > 1){
var data = helpers.shuffle(useless_facts).slice(1, count);
}
else{
var data = useless_facts[Math.floor(Math.random() * useless_facts.length)];
}
response.send({"data":data});
});
app.listen(process.env.PORT || 3000, () => console.log('Listening...'))