MCPcopy Index your code
hub / github.com/Unitech/pm2 / startWebServer

Function startWebServer

lib/HttpInterface.js:18–75  ·  view source on GitHub ↗
(pm2)

Source from the content-addressed store, hash-verified

16});
17
18function startWebServer(pm2) {
19 http.createServer(function (req, res) {
20 // Add CORS headers to allow browsers to fetch data directly
21 res.setHeader('Access-Control-Allow-Origin', '*');
22 res.setHeader('Access-Control-Allow-Headers', 'Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With');
23 res.setHeader('Access-Control-Allow-Methods', 'GET');
24
25 // We always send json
26 res.setHeader('Content-Type','application/json');
27
28 var path = urlT.parse(req.url).pathname;
29
30 if (path == '/') {
31 // Main monit route
32 pm2.list(function(err, list) {
33 if (err) {
34 return res.send(err);
35 }
36 var data = {
37 system_info: { hostname: os.hostname(),
38 uptime: os.uptime()
39 },
40 monit: { loadavg: os.loadavg(),
41 total_mem: os.totalmem(),
42 free_mem: os.freemem(),
43 cpu: os.cpus(),
44 interfaces: os.networkInterfaces()
45 },
46 processes: list
47 };
48
49 if (cst.WEB_STRIP_ENV_VARS) {
50 for (var i = data.processes.length - 1; i >= 0; i--) {
51 var proc = data.processes[i];
52
53 if (typeof proc.pm2_env === 'undefined' || typeof proc.pm2_env.env === 'undefined') continue;
54
55 delete proc.pm2_env.env;
56 }
57 }
58
59 res.statusCode = 200;
60 res.write(JSON.stringify(data));
61 return res.end();
62
63 })
64 }
65 else {
66 // 404
67 res.statusCode = 404;
68 res.write(JSON.stringify({err : '404'}));
69 return res.end();
70 }
71 }).listen(process.env.PM2_WEB_PORT || cst.WEB_PORT, cst.WEB_IPADDR, function() {
72 console.log('Web interface listening on %s:%s', cst.WEB_IPADDR, cst.WEB_PORT);
73 });
74
75}

Callers 1

HttpInterface.jsFile · 0.85

Calls 8

listenMethod · 0.80
listMethod · 0.80
uptimeMethod · 0.80
setHeaderMethod · 0.65
sendMethod · 0.65
writeMethod · 0.65
endMethod · 0.65
parseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…