-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.server.js
43 lines (34 loc) · 1.04 KB
/
test.server.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
const express = require("express");
const btoa = require("btoa");
const atob = require("atob");
const app = express();
app.use(express.urlencoded());
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET, PUT, PATCH, POST, DELETE");
res.header("Access-Control-Allow-Headers", "Content-Type");
next();
});
const port = 3000;
const userContext = {
user: 'tango-cs',
tango_hosts:{'localhost:10000':null},
device_filters: ['*/*/*'],
ext:{}
};
app.get("/user-context/cache", (req, res) => {
if(req.query.id && req.query.id === "tango-cs"){
res.send(btoa(JSON.stringify(userContext)));
}
else res.sendStatus(404);
});
app.post("/user-context/cache", (req, res) => {
if(req.body.id && req.body.id === "tango-cs"){
Object.assign(userContext,JSON.parse(atob(req.body.data)));
res.sendStatus(200);
}
else res.sendStatus(404);
});
app.listen(port, () => {
console.log("Server was started on 3000 port...");
});