2014-05-15 23:42:42 +00:00
|
|
|
var util = require('util');
|
|
|
|
var url = require('url');
|
|
|
|
var qs = require('querystring');
|
|
|
|
var os = require('os')
|
2015-04-27 15:08:14 +00:00
|
|
|
var port = process.env.PORT || process.env.port || process.env.OPENSHIFT_NODEJS_PORT || 8080;
|
2014-05-19 22:37:16 +00:00
|
|
|
var ip = process.env.OPENSHIFT_NODEJS_IP || '0.0.0.0';
|
2014-05-15 23:42:42 +00:00
|
|
|
var nodeEnv = process.env.NODE_ENV || 'unknown';
|
2015-06-04 14:16:04 +00:00
|
|
|
|
|
|
|
var express = require('express');
|
|
|
|
var app = express();
|
|
|
|
|
|
|
|
app.use(function(req, res, next) {
|
2014-05-15 23:42:42 +00:00
|
|
|
var url_parts = url.parse(req.url, true);
|
|
|
|
|
|
|
|
var body = '';
|
2014-05-19 22:37:16 +00:00
|
|
|
req.on('data', function (data) {
|
|
|
|
body += data;
|
|
|
|
});
|
|
|
|
req.on('end', function () {
|
|
|
|
var formattedBody = qs.parse(body);
|
2014-05-19 22:34:40 +00:00
|
|
|
|
2014-05-15 23:42:42 +00:00
|
|
|
res.writeHead(200, {'Content-Type': 'text/plain'});
|
|
|
|
|
2015-06-04 13:57:31 +00:00
|
|
|
res.write('Hello OpenShift World! This is a Node.js-based sample application.\n');
|
2014-05-16 01:14:52 +00:00
|
|
|
res.write('Host: ' + req.headers.host + '\n');
|
2014-05-15 23:42:42 +00:00
|
|
|
res.write('\n');
|
|
|
|
res.write('node.js Production Mode: ' + (nodeEnv == 'production' ? 'yes' : 'no') + '\n');
|
|
|
|
res.write('\n');
|
|
|
|
res.write('HTTP/' + req.httpVersion +'\n');
|
|
|
|
res.write('Request headers:\n');
|
|
|
|
res.write(util.inspect(req.headers, null) + '\n');
|
|
|
|
res.write('Request query:\n');
|
2014-05-19 22:34:40 +00:00
|
|
|
res.write(util.inspect(url_parts.query, null) + '\n');
|
2014-05-15 23:42:42 +00:00
|
|
|
res.write('Request body:\n');
|
|
|
|
res.write(util.inspect(formattedBody, null) + '\n');
|
|
|
|
res.write('\n');
|
|
|
|
res.write('Host: ' + os.hostname() + '\n');
|
|
|
|
res.write('OS Type: ' + os.type() + '\n');
|
|
|
|
res.write('OS Platform: ' + os.platform() + '\n');
|
|
|
|
res.write('OS Arch: ' + os.arch() + '\n');
|
|
|
|
res.write('OS Release: ' + os.release() + '\n');
|
|
|
|
res.write('OS Uptime: ' + os.uptime() + '\n');
|
|
|
|
res.write('OS Free memory: ' + os.freemem() / 1024 / 1024 + 'mb\n');
|
|
|
|
res.write('OS Total memory: ' + os.totalmem() / 1024 / 1024 + 'mb\n');
|
|
|
|
res.write('OS CPU count: ' + os.cpus().length + '\n');
|
|
|
|
res.write('OS CPU model: ' + os.cpus()[0].model + '\n');
|
|
|
|
res.write('OS CPU speed: ' + os.cpus()[0].speed + 'mhz\n');
|
|
|
|
res.end('\n');
|
|
|
|
});
|
2015-06-04 14:16:04 +00:00
|
|
|
next();
|
2014-05-15 23:42:42 +00:00
|
|
|
});
|
2015-06-04 14:16:04 +00:00
|
|
|
|
|
|
|
app.listen(port, ip);
|
2014-05-19 22:34:40 +00:00
|
|
|
console.log('Server running on ' + ip + ':' + port);
|