<commit_before>var koa = require('koa');
var request = require('superagent');
var mount = require('koa-mount');
var path = require('path');
var staticCache = require('koa-static-cache');
var serve = require('koa-static');
var app = module.exports = koa();


var session = require('koa-generic-session');
app.keys = ['your-session-secret'];
app.use(session());

var koaBodyParser = require('koa-bodyparser');
app.use(koaBodyParser());

var env = process.env.NODE_ENV || 'development';
var addr = process.env.PICKLETE_PORT_1337_TCP_ADDR || 'localhost';
var port = process.env.PICKLETE_PORT_1337_TCP_PORT || '1336';

//todo: use PICKLETE_ENDPOINT_URL=http://localhost:1337/

var restServerUrl = 'http://' + addr + ':' + port;

var Router = require('koa-router');
/* public routes */

var guest = new Router();

app.use(guest.middleware());

guest.get('/', function *(next){
  if (/mobile/i.test(this.request.header['user-agent'])){
    this.redirect('/app/');
  }else{
    this.redirect('/public/');
  }
});

guest.post('/auth/local/', function *(next) {
  var loginForm = this.request.body;
  loginForm.domain = extractDomain(this.request.header.referer);
  console.log("/auth/local/",loginForm);
  try {
    var result = yield request.post(restServerUrl+'/auth/local/')
    .send(loginForm)
    .set('Content-Type', 'application/json')
    .set('x-requested-with', 'XMLHttpRequest');
    this.body = result.body;
    console.log(result.body);
    if(result.body.status == 'ok'){
      this.session.login = true;
      this.session.user = result.body.user;
      console.log(this.session);
    }
  } catch (e) {
    console.log(e);
  }
});

guest.get('/user/loginStatus', function *(next){
  console.log(this);
  try {
    var status = this.session.login || false;
    this.body = status;
  } catch (e) {
    console.log(e);
  }
});

guest.get('/user/signOut', function *(next){
  console.log(this);
  try {
    this.session.login = false;
    this.session.user = null;
    this.body = this.session.login;
  } catch (e) {
    console.log(e);
  }
});

/* public routes */


var secured = new Router();

app.use(function*(next) {
  if (this.session.login || this.request.url.startsWith("/build") || this.request.url.startsWith("/app")) {
    yield next
  } else {
    yield next
    // this.redirect('/app/index.html');
  }
})
app.use(secured.middleware());<commit_msg>fix routes<commit_after>var koa = require('koa');
var request = require('superagent');
var mount = require('koa-mount');
var path = require('path');
var staticCache = require('koa-static-cache');
var serve = require('koa-static');
var app = module.exports = koa();


var session = require('koa-generic-session');
app.keys = ['your-session-secret'];
app.use(session());

var koaBodyParser = require('koa-bodyparser');
app.use(koaBodyParser());

var env = process.env.NODE_ENV || 'development';
var addr = process.env.PICKLETE_PORT_1337_TCP_ADDR || 'localhost';
var port = process.env.PICKLETE_PORT_1337_TCP_PORT || '1336';

//todo: use PICKLETE_ENDPOINT_URL=http://localhost:1337/

var restServerUrl = 'http://' + addr + ':' + port;

var Router = require('koa-router');
/* public routes */

var guest = new Router();

app.use(guest.middleware());

guest.get('/', function *(next){
  if (/mobile/i.test(this.request.header['user-agent'])){
    this.redirect('/app/');
  }else{
    this.redirect('/public/');
  }
});

guest.post('/auth/local/', function *(next) {
  var loginForm = this.request.body;
  loginForm.domain = extractDomain(this.request.header.referer);
  console.log("/auth/local/",loginForm);
  try {
    var result = yield request.post(restServerUrl+'/auth/local/')
    .send(loginForm)
    .set('Content-Type', 'application/json')
    .set('x-requested-with', 'XMLHttpRequest');
    this.body = result.body;
    console.log(result.body);
    if(result.body.status == 'ok'){
      this.session.login = true;
      this.session.user = result.body.user;
      console.log(this.session);
    }
  } catch (e) {
    console.log(e);
  }
});

guest.get('/user/loginStatus', function *(next){
  console.log(this);
  try {
    var status = this.session.login || false;
    this.body = status;
  } catch (e) {
    console.log(e);
  }
});

guest.get('/user/signOut', function *(next){
  console.log(this);
  try {
    this.session.login = false;
    this.session.user = null;
    this.body = this.session.login;
  } catch (e) {
    console.log(e);
  }
});

/* public routes */


var secured = new Router();

app.use(function*(next) {
  if (this.session.login ||
     this.request.url.startsWith("/build") ||
     this.request.url.startsWith("/app") ||
     this.request.url.startsWith("/public")) {
    yield next
  } else {
    // yield next
    this.redirect('/app/index.html');
  }
})
app.use(secured.middleware());
{'fraction_non_alphanumeric': 0.19230769230769232, 'fraction_numerical': 0.006688963210702341, 'mean_word_length': 3.6592015579357353, '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': '7157431', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1658, 'n_words': 297}