<commit_before>var cors = require('cors');
var express = require('express');

var PORT = process.env.PORT || 5000;

var socialButtonsServer = require('./lib/social-buttons-server-middleware.js');

var app = express();

var morgan = require("morgan");

var expressLogger = morgan("combined", {
    skip: function(req, res) {
        return res.statusCode < 400;
    }
});

app.use(expressLogger);


// Use CORS domain whitelisting.
// Requires that Cloudflare (or other CDNs) let the right headers pass to and from the browser.
function getWhitelist(){
  var whitelist = [];

  if(process.env.DOMAIN_WHITELIST) {
    whitelist = process.env.DOMAIN_WHITELIST.split(",");
  }

  return whitelist;
}

var whitelist = getWhitelist();

if(whitelist.length === 0){
  console.warn("The CORS domain whitelist is empty. This might lead to problems when requests arrive originate from domains other than the one the server is running on.")
}

var corsOptions = {
  origin: function (origin, cb) {
    cb(null, whitelist.indexOf(origin) !== -1);
  }
};

app.use(cors(corsOptions));

app.options('*', cors(corsOptions));



app.use("/", socialButtonsServer());

app.listen(PORT, function () {
  console.log('Listening on ' + PORT);
});
<commit_msg>Clean up social-buttons-server.js<commit_after>var express = require("express"),

    PORT = process.env.PORT || 5000,

    cors = require("cors"),

    socialButtonsServer = require("./lib/social-buttons-server-middleware.js"),

    morgan = require("morgan"),
    expressLogger = morgan("combined", {
        skip: function(req, res) {
            return res.statusCode < 400;
        }
    }),

    // Use CORS domain whitelisting.
    // Requires that Cloudflare (or other CDNs) let the right headers pass to and from the browser.
    getWhitelist = function() {
        var whitelist = [];

        if (process.env.DOMAIN_WHITELIST) {
            whitelist = process.env.DOMAIN_WHITELIST.split(",");
        }

        return whitelist;
    },
    whitelist = getWhitelist(),
    corsOptions = {
        origin: function(origin, cb) {
            cb(null, whitelist.indexOf(origin) !== -1);
        }
    },

    app = express();

app.use(expressLogger);


if (whitelist.length === 0) {
    console.warn("The CORS domain whitelist is empty. This might lead to problems when requests arrive originate from domains other than the one the server is running on.")
}

app.use(cors(corsOptions));

app.options("*", cors(corsOptions));



app.use("/", socialButtonsServer());

app.listen(PORT, function() {
    console.log("Listening on " + PORT);
});
{'fraction_non_alphanumeric': 0.14202786377708979, 'fraction_numerical': 0.00696594427244582, 'mean_word_length': 3.3518518518518516, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7453356', 'n_tokens_mistral': 840, 'n_tokens_neox': 796, 'n_words': 211}