-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdapi.js
148 lines (119 loc) · 3.05 KB
/
sdapi.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
var btoa = require('btoa');
var path = require('path');
var https = require('https');
var jsonfile = require('jsonfile');
var bodyParser = require('body-parser');
var exports = module.exports = {}
var config = {};
var file = './config/data.json';
var sandbox = "";
var username = "";
var password = "";
var auth = "";
var responseHeaders = "";
var responseBody = "";
readConfig = function() {
jsonfile.readFile(file, function(err, obj) {
config = obj;
});
};
writeConfig = function() {
var obj = {
sandbox: sandbox,
username: username,
password: password,
};
jsonfile.writeFile(file, obj, function(err) {
console.error(err)
})
};
exports.start = function () {
var express = require('express');
var app = express();
app.use(bodyParser.urlencoded({
extended: false
}))
app.use(bodyParser.json());
app.get('/', function(req, res) {
app.use(express.static('html'));
res.sendFile(path.join(__dirname + '/html/index.html'));
});
app.post('/saveConfig', function(req, res) {
sandbox = req.body.sandbox;
username = req.body.username;
password = req.body.password;
writeConfig();
});
app.get('/readConfig', function(req, res) {
readConfig();
res.send(config);
});
app.post('/connect', function(req, res) {
sandbox = req.body.sandbox;
username = req.body.username;
password = req.body.password;
connect(res);
});
app.get('/getBreakPoints', function(req, res) {
sandbox = req.body.sandbox;
username = req.body.username;
password = req.body.password;
getBreakPoints(res);
});
app.listen(3000, function() {
console.log('Example app listening on port 3000!');
});
};
connect = function(nodeRes) {
var options = {
host: sandbox,
port: '443',
path: '/s/-/dw/debugger/v1_0/client',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': make_base_auth(username, password),
'x-dw-client-id': 'debugger'
}
};
var req = https.request(options, function(res) {
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
responseHeaders = res.headers;
auth = res.req._headers.authorization;
res.on('data', function(d) {
process.stdout.write(d);
nodeRes.send(d);
});
});
req.end();
};
getBreakPoints = function(nodeRes) {
var options = {
host: config.sandbox,
port: '443',
path: '/s/-/dw/debugger/v1_0/breakpoints',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': auth,
'x-dw-client-id': 'debugger'
}
};
var req = https.request(options, function(res) {
console.log("statusCode: ", res.statusCode);
res.on('data', function(d) {
process.stdout.write(d);
responseBody = d;
nodeRes.send(d);
req.end();
});
});
};
exports.init = function() {
};
make_base_auth = function(user, password) {
var tok = user + ':' + password;
var hash = btoa(tok);
return 'Basic ' + hash;
}