forked from HugoDF/express-redis-docker
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (23 loc) · 720 Bytes
/
server.js
File metadata and controls
29 lines (23 loc) · 720 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
const express = require('express');
const morgan = require('morgan');
const app = express();
app.use(morgan('combined'));
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}`);
});