-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp-web.js
47 lines (41 loc) · 1.1 KB
/
app-web.js
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
const ds = require("./lib/keyvalue-db").async;
const express = require("express");
const app = express();
app.get('/read', function (req, res, next) {
let key = req.query.key;
ds.readkey(key).then(x => {
return res.status(200).send(JSON.parse(x));
}).catch(x => {
return res.status(400).send(x);
})
})
app.post('/create', function (req, res, next) {
let key = req.query.key;
let value = req.query.value;
let timeout = req.query.timeout ? req.query.timeout : 0;
ds.createkey(key, value, timeout)
.then(x => {
return res.status(201).send(x);
}).catch(x => {
return res.status(400).send(x);
})
})
app.get('/delete', function (req, res, next) {
let key = req.query.key;
ds.deletekey(key).then(x => {
return res.status(200).send(x);
}).catch(x => {
return res.status(400).send(x);
})
})
app.get('/setpath', function (req, res, next) {
let key = req.query.key;
ds.setpath(key).then(x => {
return res.status(200).send(x);
}).catch(x => {
return res.status(400).send(x);
})
})
app.listen(3000, () => {
console.log('Server is running!!: 3000')
})