{"size": 653, "ext": "js", "max_stars_repo_path": "src/server.js", "max_stars_repo_name": "brendandburns/admission-control-sdk", "max_stars_repo_stars_event_min_datetime": "2022-02-26T19:51:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T15:36:33.000Z", "max_issues_repo_path": "src/server.js", "max_issues_repo_name": "brendandburns/admission-control-sdk", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/server.js", "max_forks_repo_name": "brendandburns/admission-control-sdk", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.2083333333, "max_line_length": 64, "alphanum_fraction": 0.5114854518}
const https = require('https');
const fs = require('fs');

exports.serve = (controllerName, handler) => {
    const options = {
        key: fs.readFileSync(`certs/${controllerName}-key.pem`),
        cert: fs.readFileSync(`certs/${controllerName}-crt.pem`)
    };
    
    https.createServer(options, (req, res) => {    
        let objStr = '';
        req.on('data', chunk => {
            objStr += chunk;
        })
        req.on('end', () => {
            const obj = JSON.parse(objStr);
            const result = handler(obj);
    
            res.writeHead(200);
            res.end(JSON.stringify(result));
        });
    }).listen(8443);
}
