MCPcopy Create free account
hub / github.com/acode/cli / run

Method run

cli/commands/hostnames/add.js:31–73  ·  view source on GitHub ↗
(params, callback)

Source from the content-addressed store, hash-verified

29 }
30
31 run(params, callback) {
32
33 let host = 'api.autocode.com';
34 let port = 443;
35
36 let source = params.args[0] || '';
37 let target = params.args[1] || '';
38
39 let versionString = target.split('[@')[1];
40 versionString = versionString && versionString.replace(']', '');
41 let service = target.split('[@')[0];
42 let urlComponentArray = [service.split('.')[1], service.split('.')[0], 'api.stdlib.com'];
43
44 if (versionString) {
45 versionString = versionString.split('.').join('-');
46 urlComponentArray.unshift(versionString);
47 }
48
49 let hostname = (params.flags.h && params.flags.h[0]) || '';
50 let matches = hostname.match(/^(https?:\/\/)?(.*?)(:\d+)?$/);
51
52 if (hostname && matches) {
53 host = matches[2];
54 port = parseInt((matches[3] || '').substr(1) || (hostname.indexOf('https') === 0 ? 443 : 80));
55 }
56
57 let resource = new APIResource(host, port);
58 resource.authorize(config.get('ACCESS_TOKEN'));
59
60 resource.request('v1/hostname_routes').create({}, {
61 hostname: source,
62 target: urlComponentArray.join('.')
63 }, (err, response) => {
64
65 if (err) {
66 return callback(err);
67 }
68
69 return callback(null, `Successfully added route from "${response.data[0].formatted_hostname}" to "${target}"!`);
70
71 });
72
73 }
74
75}
76

Callers

nothing calls this directly

Calls 2

getMethod · 0.80
requestMethod · 0.80

Tested by

no test coverage detected