<commit_before>module.exports = function (badgerService) {
  var env = require('./environments');
  var express = require('express'),
    app = express(),
    bodyParser = require('body-parser'),
    path = require('path');

  app.set('view engine', 'jade');
  app.use(express.static(path.join(__dirname, '..', '/public')));
  app.use(bodyParser.json()); // to support JSON-encoded bodies
  app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
    extended: true
  }));

  function returnBadges(getBadges, request, response) {
    getBadges(function (error, badges) {
      if (error !== null) {
        console.log('Get error from return Badges ' + error);
        response.send(error);
      } else {
        if (request.query.pretty) {
          response.render(path.join(__dirname, '..', '/public/code.jade'), {
            data: JSON.stringify(badges, null, 2)
          });
        } else {
          response.json(badges);
        }
      }
    });
  }

  // Set the client credentials and the OAuth2 server
  var credentials = {
    clientID: env.get('ORCID_AUTH_CLIENT_ID'),
    clientSecret: env.get('ORCID_AUTH_CLIENT_SECRET'),
    site: env.get('ORCID_AUTH_SITE'),
    tokenPath: env.get('ORCID_AUTH_TOKEN_PATH')
  };

  // Initialize the OAuth2 Library for ORCID
  var oauth2 = require('simple-oauth2')(credentials);

  // TODO: review proper session use
  var session = require('express-session');
  app.use(session({
    secret: env.get('SESSION_SECRET'),
    cookie: {}
  }));

  // Build ORCID authorization oauth2 URI
  var authorizationUri = oauth2.authCode.authorizeURL({
    redirect_uri: env.get('ORCID_REDIRECT_URI'),
    scope: '/authenticate',
    state: 'none'
  });

  // Redirect example using Express (see http://expressjs.com/api.html#res.redirect)<commit_msg>Enable CORS * http://enable-cors.org/server_expressjs.html<commit_after>module.exports = function (badgerService) {
  var env = require('./environments');
  var express = require('express'),
    app = express(),
    bodyParser = require('body-parser'),
    path = require('path');

  app.set('view engine', 'jade');
  app.use(express.static(path.join(__dirname, '..', '/public')));
  app.use(bodyParser.json()); // to support JSON-encoded bodies
  app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
    extended: true
  }));

  function returnBadges(getBadges, request, response) {
    getBadges(function (error, badges) {
      if (error !== null) {
        console.log('Get error from return Badges ' + error);
        response.send(error);
      } else {
        if (request.query.pretty) {
          response.render(path.join(__dirname, '..', '/public/code.jade'), {
            data: JSON.stringify(badges, null, 2)
          });
        } else {
          response.json(badges);
        }
      }
    });
  }

  // Set the client credentials and the OAuth2 server
  var credentials = {
    clientID: env.get('ORCID_AUTH_CLIENT_ID'),
    clientSecret: env.get('ORCID_AUTH_CLIENT_SECRET'),
    site: env.get('ORCID_AUTH_SITE'),
    tokenPath: env.get('ORCID_AUTH_TOKEN_PATH')
  };

  // Initialize the OAuth2 Library for ORCID
  var oauth2 = require('simple-oauth2')(credentials);

  // TODO: review proper session use
  var session = require('express-session');
  app.use(session({
    secret: env.get('SESSION_SECRET'),
    cookie: {}
  }));

  // Build ORCID authorization oauth2 URI
  var authorizationUri = oauth2.authCode.authorizeURL({
    redirect_uri: env.get('ORCID_REDIRECT_URI'),
    scope: '/authenticate',
    state: 'none'
  });

  app.use(function (req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
    next();
  });

  // Redirect example using Express (see http://expressjs.com/api.html#res.redirect)
{'fraction_non_alphanumeric': 0.1545643153526971, 'fraction_numerical': 0.0036307053941908715, 'mean_word_length': 3.187839305103149, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1136762', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1221, 'n_words': 250}