Repository navigation
Expand file tree
/
Copy pathserver.js
More file actions
88 lines (79 loc) · 2.4 KB
/
Copy pathserver.js
File metadata and controls
88 lines (79 loc) · 2.4 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const express = require("express");
const app = express();
const axios = require("axios").default;
const crypto = require("crypto");
const querystring = require('querystring');
var API;
var Secret;
app.use(express.static("./public"));
app.use(express.json());
app.use(express.urlencoded({extended: true}));
app.get("/test", (req, res)=>{
res.sendFile(__dirname + "/public/PlayPlay/index.html");
});
app.get("/", (req,res)=>{
res.sendFile("/public/index.html")
});
app.get("/history", (req,res)=>{
res.sendFile(__dirname + "/public/historyCheck/history.html");
});
async function postreq(obj, APIKey, secretKey) {
// Initialize variable
var output;
const data = obj;
data.nonce = new Date().getTime();
const secret_key = secretKey;
const hmac = crypto.createHmac("sha512", secret_key);
const dataquery = querystring.stringify(data);
hmac.update(dataquery);
const headers = {
Key: APIKey,
Sign: hmac.digest("hex")
};
await axios.post("https://indodax.com/tapi", dataquery, {headers: headers}).then((res)=>{
output = res.data;
}).catch((err)=>{
console.error(err);
});
return output;
}
const validationRegex = /[\"\,\.\'\<\>\=\;\.\!\`\\\/\(\)\{\}\[\]]/i;
app.post("/api", (req, res)=>{
var prohibited = false;
for (const [key, value] of Object.entries(req.body)) {
if(validationRegex.test(value)){prohibited = true};
}
if (prohibited == false) {
var api = req.body.api, secret = req.body.secret;
delete req.body.api;
delete req.body.secret;
postreq(req.body, api, secret).then((data)=>{
var s = data.return;
res.json(s);
res.end();
}).catch((err)=>{console.error(err)});
} else {
res.send("PROHIBITED");
}
});
app.post("/history", (req, res)=>{
var prohibited = false;
for (const [key, value] of Object.entries(req.body)) {
if(validationRegex.test(value)){prohibited = true};
}
if (prohibited == false) {
var obj =
{
method: req.body.method,
pair: req.body.pair
};
postreq(obj, req.body.api, req.body.secret).then((data)=>{
var s = data.return.trades;
res.json(s);
res.end();
}).catch((err)=>{console.error(err)});
} else {
res.send("PROHIBITED");
}
});
app.listen(process.env.PORT || 3000);