<commit_before>'use strict';

const fs = require('fs');
var http = require('http');
var config = require('./config.js');

exports.init = function(xpress) {
  let app = xpress;
  //app.set('trust proxy', 1);
  app.get('/', function(req, res) {
  	res.redirect('/app');
  })
  app.all('/app/*', function (req, res) {
  	res.redirect('/app');
  });
  app.all('/api', function (req, res) {
    //console.log('api root request');
    res.json({data:"battlecruiser operational"});
  });
  app.post('/api/login', function (req, res) {
    console.log("request ip:", req.connection.remoteAddress);
    console.log('login request', req.headers);
    console.log('sess', req.session);
    var user = req.body;
    var api = require('./login');
    api.login(user, (result) => {
      var cookiesArr = result.headers['set-cookie'];
      req.session.remoteCookies = cookiesArr;
      if(result.statusCode == 200) {
        api.getUserInfo(cookiesArr, (result) => {
          let a = result.data;
          let b = a.user.User;
          let c = a.user.UserLevel;
          if(!!b.avatar_img) parseAvatar(b.avatar_img);
          let answer = {
            id          : b.id,
            avatar      : b.avatar,
            avatar_img  : b.avatar_img,
            username    : b.username,
            vd_balance  : b.vd_balance,
            vg_balance  : b.vg_balance,
            max_health  : b.max_health,
            health      : b.health,
            energy      : b.energy,
            max_energy  : b.max_energy,
            prestige    : b.prestige,
            city_id     : b.city_id,
            last_up_energy        : b.last_up_energy,
            delta_recovery_energy : b.delta_recovery_energy,
            military_rank         : b.military_rank,
            military_rank_img     : b.military_rank_img,
            level               : c.level,
            xp                  : c.xp,
            nextLevelExperience : c.nextLevelExperience
          };
          res.json({
            data    :answer,
            error   :0,
            message :""
          });
        })
      } else {
        res.json({
          error:result.statusCode,
          message:result.data,
          data:JSON.stringify(result)
        });
      }
    });
  });
  app.get('/api/corps', function (req, res) {
    let sessCookies = req.session.remoteCookies;
    //console.log('corps list request', sessCookies);
    if(!!sessCookies) {
      //console.log("loading api...");
      var api = require('./corps');
      //console.log("calling getCorpsList");
      api.getCorpsList(sessCookies, (result) => {
        let answer = result.data.corporations;
        //console.log("getCorpsList finished", answer);
        res.json({
          data    : answer,<commit_msg>login problems error handler bugfix<commit_after>'use strict';

const fs = require('fs');
var http = require('http');
var config = require('./config.js');

exports.init = function(xpress) {
  let app = xpress;
  //app.set('trust proxy', 1);
  app.get('/', function(req, res) {
  	res.redirect('/app');
  })
  app.all('/app/*', function (req, res) {
  	res.redirect('/app');
  });
  app.all('/api', function (req, res) {
    //console.log('api root request');
    res.json({data:"battlecruiser operational"});
  });
  app.post('/api/login', function (req, res) {
    console.log("request ip:", req.connection.remoteAddress);
    console.log('login request', req.headers);
    console.log('sess', req.session);
    var user = req.body;
    var api = require('./login');
    api.login(user, (result) => {
			console.log("login result:", result);
      var cookiesArr = result.headers['set-cookie'];
      req.session.remoteCookies = cookiesArr;
      if(result.statusCode == 200) {
        api.getUserInfo(cookiesArr, (result) => {
					if(result.statusCode == 200) {
	          let a = result.data;
	          let b = a.user.User;
	          let c = a.user.UserLevel;
	          if(!!b.avatar_img) parseAvatar(b.avatar_img);
	          let answer = {
	            id          : b.id,
	            avatar      : b.avatar,
	            avatar_img  : b.avatar_img,
	            username    : b.username,
	            vd_balance  : b.vd_balance,
	            vg_balance  : b.vg_balance,
	            max_health  : b.max_health,
	            health      : b.health,
	            energy      : b.energy,
	            max_energy  : b.max_energy,
	            prestige    : b.prestige,
	            city_id     : b.city_id,
	            last_up_energy        : b.last_up_energy,
	            delta_recovery_energy : b.delta_recovery_energy,
	            military_rank         : b.military_rank,
	            military_rank_img     : b.military_rank_img,
	            level               : c.level,
	            xp                  : c.xp,
	            nextLevelExperience : c.nextLevelExperience
	          };
	          res.json({
	            data    :answer,
	            error   :0,
	            message :""
	          });
					} else {
						res.json({
		          error:result.statusCode,
		          message:result.data,
		          data:JSON.stringify(result)
		        });
					}
        })
      } else {
        res.json({
          error:result.statusCode,
          message:result.data,
          data:JSON.stringify(result)
        });
      }
    });
  });
  app.get('/api/corps', function (req, res) {
    let sessCookies = req.session.remoteCookies;
    //console.log('corps list request', sessCookies);
    if(!!sessCookies) {
      //console.log("loading api...");
      var api = require('./corps');
      //console.log("calling getCorpsList");
      api.getCorpsList(sessCookies, (result) => {
        let answer = result.data.corporations;
        //console.log("getCorpsList finished", answer);
        res.json({
          data    : answer,
{'fraction_non_alphanumeric': 0.14256233877901978, 'fraction_numerical': 0.002235597592433362, 'mean_word_length': 1.7603227337446608, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1939206', 'n_tokens_mistral': 1873, 'n_tokens_neox': 1768, 'n_words': 329}