Project

General

Profile

« Previous | Next » 

Revision 49714

Add host for redis, get proper answer, add cors

View differences:

cache.js
3 3
const request = require('superagent');
4 4
const PORT = process.env.PORT;
5 5
const REDIS_PORT = process.env.REDIS_PORT;
6
const REDIS_HOST = process.env.REDIS_HOST;
6 7

  
7 8
const app = express();
8
const client = redis.createClient(REDIS_PORT);
9
const client = redis.createClient(REDIS_PORT, REDIS_HOST);
9 10

  
10
function respond(org, numberOfRepos) {
11
    return `Organization "${org}" has ${numberOfRepos} public repositories.`;
12
}
11
// function respond(org, numberOfRepos) {
12
//     return `Organization "${org}" has ${numberOfRepos} public repositories.`;
13
// }
13 14

  
14 15
function cache(req, res, next) {
15 16
    const url = req.query.url;
16 17
    client.get(url, function (err, data) {
17 18
        if (data != null) {
18
            res.send(respond(url, data));
19
            res.send(data);
19 20
        } else {
20 21
            next();
21 22
        }
......
51 52

  
52 53
          // response.body contains an array of public repositories
53 54
          // var repoNumber = response.body.length;
54
          res.send(response);
55
          res.send(response.body);
55 56
    })
56 57
  }
57 58
})

Also available in: Unified diff