-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (46 loc) · 1.28 KB
/
index.js
File metadata and controls
50 lines (46 loc) · 1.28 KB
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
const Hapi = require('hapi');
const JFile = require('jfile');
const async = require('async');
const filter = require('lodash').filter;
const fetchPluginData = require('./fetch-plugin-data');
const server = new Hapi.Server();
server.connection({
host: 'localhost',
port: 3000
});
server.route({
method: 'GET',
path:'/',
handler: function (request, reply) {
return reply.redirect('https://github.com/secretpizzaparty/better-plugin-recommendations-server');
}
});
server.route({
method: 'GET',
path:'/api/plugin-recommendations',
handler: function (request, reply) {
const pluginsFile = new JFile( __dirname + '/plugins.txt' );
const pluginsToFetch = filter( pluginsFile.lines );
return async.map(
pluginsToFetch,
fetchPluginData,
( err, results ) => {
const plugins = filter(results);
return reply({
info: {
page: 1,
pages: 1,
results: plugins.length,
},
plugins
});
}
);
}
});
server.start((err) => {
if (err) {
throw err;
}
console.log('Server running at:', server.info.uri);
});