<commit_before>var express = require('express'),
  app = express(),
  path = require('path'),
  port = (process.argv[2] || 8000),
  nano = require('nano')('http://localhost:5984'),
  _ = require('underscore'),
  dbName = 'futurice-super',
  database = nano.use(dbName)
;

app.get('/api/view/:viewName', function(req, res) {

  console.log("View: "+req.params.viewName);
  database.get('_design/views/_view/'+req.params.viewName).pipe(res);

});

app.get('/api/tribes', function(req, res) {

  console.log("Tribes");

  database.get('_design/views/_view/tribes?group=true', function(err, body) {
    var response = body.rows.map(function (row) {
      return {
        name: row.key,
        prettyName: row.key.match(/- ?([a-z0-9 ]+?)$/i)[1]
      };
    });

    res.json(response);
  });

});

app.post('/api/favorites/:projectId', function(req, res){
  var user = req.headers['x-forwarded-user'];

  if (!user){
    res.status(400);

  } else {

    database.get(req.params.projectId, function(err, body){
      if (err) {
        if (err.status_code === 404) {
          res.status(404);
        } else {
          console.log(err);
        }
      } else {
        if (!body.FavoritedBy){
          body.FavoritedBy = [];
        }

        if (!_.contains(body.FavoritedBy, user)) {
          body.FavoritedBy.push(user);
        }

        database.insert(body, body.id, function(){
            res.send('User '+user+' favorited opportunity '+ body.Name);
          }, function(err){
            console.log(err);
        });

      }
    });
  }
});

app.get('/api/*', function(req, res) {

  console.log("GET " + req.params[0]);
  database.get(req.params[0]).pipe(res);

});


app.use(express.static(__dirname));
<commit_msg>Add api endpoint to return current user<commit_after>var express = require('express'),
  app = express(),
  path = require('path'),
  port = (process.argv[2] || 8000),
  nano = require('nano')('http://localhost:5984'),
  _ = require('underscore'),
  dbName = 'futurice-super',
  database = nano.use(dbName)
;

app.get('/api/view/:viewName', function(req, res) {

  console.log("View: "+req.params.viewName);
  database.get('_design/views/_view/'+req.params.viewName).pipe(res);

});

app.get('/api/tribes', function(req, res) {

  console.log("Tribes");

  database.get('_design/views/_view/tribes?group=true', function(err, body) {
    var response = body.rows.map(function (row) {
      return {
        name: row.key,
        prettyName: row.key.match(/- ?([a-z0-9 ]+?)$/i)[1]
      };
    });

    res.json(response);
  });

});

app.post('/api/favorites/:projectId', function(req, res){
  var user = req.headers['x-forwarded-user'];

  if (!user){
    res.status(400);

  } else {

    database.get(req.params.projectId, function(err, body){
      if (err) {
        if (err.status_code === 404) {
          res.status(404);
        } else {
          console.log(err);
        }
      } else {
        if (!body.FavoritedBy){
          body.FavoritedBy = [];
        }

        if (!_.contains(body.FavoritedBy, user)) {
          body.FavoritedBy.push(user);
        }

        database.insert(body, body.id, function(){
            res.send('User '+user+' favorited opportunity '+ body.Name);
          }, function(err){
            console.log(err);
        });

      }
    });
  }
});

app.get('/api/user', function(req, res){
  res.send(req.headers['x-forwarded-user']);
});

app.get('/api/*', function(req, res) {

  console.log("GET " + req.params[0]);
  database.get(req.params[0]).pipe(res);

});


app.use(express.static(__dirname));

{'fraction_non_alphanumeric': 0.201115760111576, 'fraction_numerical': 0.012831241283124128, 'mean_word_length': 2.636916835699797, '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': '1288936', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1245, 'n_words': 186}