-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
46 lines (35 loc) · 1.09 KB
/
util.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
import settings from './settings'
import fetch from 'isomorphic-fetch'
var request = require('request')
export function GetEnvironmentVar(varname, defaultvalue) {
var result = process.env[varname];
if (result != undefined)
return result;
else
return defaultvalue;
}
export function makeRequest(uri, data = {}) {
const url = `http://${settings.api.host}/${settings.api.version}/${uri}`
data = {
...data,
headers: {
'Authorization': `ApiKey ${settings.api.user}:${settings.api.token}`,
...data.headers,
},
}
return new Promise((resolve, reject) => {
request({ url, headers: data.headers }, (error, res, body) => {
if (error) {
reject(Error(error));
}
else if (res && res.statusCode >= 400) {
reject(Error(`Bad response from server: [${res.statusCode}] ${res}`));
} else {
resolve(JSON.parse(body));
}
});
})
}
export function getStorenameFromPath(path) {
return path.split('/')[1];
}