{"size": 1813, "ext": "js", "max_stars_repo_path": "app.js", "max_stars_repo_name": "faustixro/white-lotus-square-server", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app.js", "max_issues_repo_name": "faustixro/white-lotus-square-server", "max_issues_repo_issues_event_min_datetime": "2017-12-02T16:09:46.000Z", "max_issues_repo_issues_event_max_datetime": "2019-01-26T14:39:48.000Z", "max_forks_repo_path": "app.js", "max_forks_repo_name": "faustixro/white-lotus-square-server", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 28.7777777778, "max_line_length": 76, "alphanum_fraction": 0.6536127965}
'use strict';

const http = require('http'),
    fs = require('fs'),
    path = require('path'),
    contentTypes = require('./utils/content-types'),
    sysInfo = require('./utils/sys-info'),
    express = require('express'),
    bodyParser = require('body-parser'),
    connectToDb = require('./utils/db-utils'),
    cors = require('cors');

let port = process.env.PORT || process.env.OPENSHIFT_NODEJS_PORT || 8080,
    ip   = process.env.IP   || process.env.OPENSHIFT_NODEJS_IP || '0.0.0.0';

let personsRoutes = require('./routes/persons');
let pSquareRoutes = require('./routes/psquare');
let baziRoutes = require('./routes/bazi');

let app = express();

app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(cors());

app.use('/api', personsRoutes);
app.use('/api', pSquareRoutes);
app.use('/api', baziRoutes);
app.use(express.static('static'));
app.get('/health', function(req, res) {
    res.writeHead(200);
    res.end();
});

// Health check for OpenShift
app.get('/pagecount', function(req, res) {
    res.writeHead(200);
    res.end();
});
app.get('/routes', function(req, res) {
    let router = express.Router();
    res.setHeader('Content-Type', 'application/json');
    res.setHeader('Cache-Control', 'no-cache, no-store');
    res.end(JSON.stringify(router.stack));
});

function getSysInfo(req, res) {
    res.setHeader('Content-Type', 'application/json');
    res.setHeader('Cache-Control', 'no-cache, no-store');
    res.end(JSON.stringify(sysInfo[req.originalUrl.slice(6)]()));
}
app.get('/info/poll', getSysInfo);
app.get('/info/gen', getSysInfo);

connectToDb();

app.listen(port, ip, function () {
    console.log(`Application worker ${process.pid} started...`);
    console.log('Express server listening on ' + ip + ':' + port);
});

module.exports = app;
