-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
62 lines (48 loc) · 1.75 KB
/
test.js
File metadata and controls
62 lines (48 loc) · 1.75 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
var path = require('path');
var ngrok = require('ngrok');
var job = require('./job');
var waitOn = require('wait-on');
function test(apiKey, protocol, domain, port) {
if (!apiKey) {
throw("You must set an api key variable, either by setting as an environment variable or by passing in the `--api-key` parameter.");
}
if (!port) {
port = 80;
console.warn(`No port cli or environment variable specified, defaulting to ${port}`);
}
if (!domain) {
domain = 'localhost';
}
var target = `${protocol}://${domain}:${port}`;
console.log(`Waiting up to 60s for '${target}' to become available`);
waitOn({resources: [target], interval: 1000, timeout: 60000}, err => {
if (err) {
throw(`Unable to connect to '${target}'`)
}
console.log(`Connected to '${target}'`);
ngrok.connect({
proto: 'http',
addr: port
}, test);
});
function test(err, url) {
if (err) {
throw(`Failed to create the ngrok proxy: ${JSON.stringify(err)}`);
}
console.log('Created ngrok proxy: ', url);
job.create(url, apiKey, (err, jobId) => {
console.log(`Created Obehave job with id: ${jobId}`);
setInterval(() => job.status(jobId, apiKey, (err, status) => {
console.log(`Obehave job '${jobId}' has status '${status}'`);
if (status === 'FINISHED') {
process.exit(0)
}
if (status === 'FAILED') {
console.error(`To view details, go to 'https://app.obehave.io/detail/${jobId}'.`);
process.exit(1);
}
}), 5000)
})
}
}
module.exports = test;