-
Notifications
You must be signed in to change notification settings - Fork 869
/
index.js
43 lines (35 loc) · 1.21 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
var express = require('express');
var app = express();
var path = require('path');
var server = require('http').createServer(app);
var axios = require('axios');
var querystring = require('querystring');
require('dotenv').config();
var bodyParser = require('body-parser');
app.use( bodyParser.json() );
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/index.html'));
});
var instance = axios.create({
baseURL: 'https://api.imgur.com/3/',
headers: { 'Authorization': 'Client-ID ' + process.env.IMGUR_CLIENT_ID }
});
app.get('/search/:query', function(req, res) {
const url = 'gallery/search/top/0/?' + querystring.stringify({ q: req.params.query });
instance.get(url)
.then(function (result) {
res.send(result.data.data.filter(item => !item.is_album && !item.nsfw && !item.animated));
})
.catch(function (error) {
console.log(error);
})
;
});
app.use('/node_modules', express.static(path.join(__dirname, 'node_modules')));
app.use('/public', express.static(path.join(__dirname, 'public')));
if (process.env.NODE_ENV !== 'production') {
require('reload')(app);
}
server.listen(process.env.PORT, function () {
console.log('Listening on port '.concat(process.env.PORT))
});