-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (21 loc) · 656 Bytes
/
server.js
File metadata and controls
27 lines (21 loc) · 656 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
const express = require('express');
const app = express();
const redisClient = require('./redis-client');
app.get('/store/:key', async (req, res) => {
const { key } = req.params;
const value = req.query;
await redisClient.setAsync(key, JSON.stringify(value));
return res.send('Success');
});
app.get('/:key', async (req, res) => {
const { key } = req.params;
const rawData = await redisClient.getAsync(key);
return res.json(JSON.parse(rawData));
});
app.get('/', (req, res) => {
return res.send('Hello world');
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`);
});