-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
35 lines (27 loc) · 1022 Bytes
/
app.js
File metadata and controls
35 lines (27 loc) · 1022 Bytes
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
const express = require('express');
const axios = require('axios');
const redis = require('redis');
const app = express();
// const redisClient = redis.createClient();
const redisPassword = "123456789" ;
const redisClient = redis.createClient({
host : '127.0.0.1',
port : 6379,
no_ready_check: true,
auth_pass: redisPassword,
});
app.get('/', (req, res) => {
const username = req.query.username || 'arsarawut';
const url = `https://api.github.com/users/${username}`;
redisClient.get(username, async (err, reply) => {
if (reply) {
return res.json(JSON.parse(reply));
}
const response = await axios.get(url);
redisClient.setex(username, 60, JSON.stringify(response.data));
return res.json(response.data);
});
});
app.listen(3000, () => {
console.log('running');
});