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

Class HTTPCommand

cli/commands/http.js:12–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10const DEFAULT_BUILD = 'faaslang';
11
12class HTTPCommand extends Command {
13
14 constructor() {
15
16 super('http');
17
18 }
19
20 help() {
21
22 return {
23 description: 'Creates HTTP Server for Current Service',
24 flags: {
25 p: 'Port (default 8170)'
26 },
27 vflags: {
28 port: 'Port (default 8170)'
29 }
30 };
31
32 }
33
34 run(params, callback) {
35
36 let pkg;
37 let env;
38
39 try {
40 pkg = serviceConfig.get();
41 } catch(err) {
42 return callback(err);
43 }
44
45 try {
46 env = require(path.join(process.cwd(), 'env.json'));
47 } catch (e) {
48 console.error(e);
49 return callback(new Error('Invalid env.json in this directory'));
50 }
51
52 let build = pkg.stdlib.build;
53 let serviceName = pkg.stdlib.name;
54 let localRoute = pkg.stdlib.local.route;
55 let route = localRoute || serviceName;
56 let port = (params.flags.p || params.vflags.port || [])[0] || parseInt(pkg.stdlib.local.port) || 8170;
57
58 route = route.startsWith('/') ? route : '/' + route;
59
60 if (build !== 'legacy') {
61 child_process.fork(path.join(__dirname, '../local_http.js'), [`PORT=${port}`, `ROUTE=${route}`, `NAME=${serviceName}`]);
62 } else {
63 parser.check(err => parser.createServer(pkg, port, !!err));
64 }
65
66 }
67
68}
69

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected