<commit_before>const querystring = require('querystring');
var session = require('express-session');

const conf = require('./conf.js');


///var host = 'occinterface.herokuapp.com'
var port = process.env.PORT || 3000;
var proxyDefaultTarget = conf.backendURL;

//we define the backendURL as a gloabl variable
// window.backendURL = proxyDefaultTarget;

var proxyOptions = {
  path : '/proxiedOCCIServer/**',
  target: proxyDefaultTarget,
  rewrite: function(req) {
    req.url = req.url.replace(new RegExp('^\/proxiedOCCIServer'), '');
  },
  changeOrigin: true
};

function setup(app) {
  // update the proxied target URL :
  // test using ex. http://localhost:3000/conf?proxyTarget=http://malmo.lizenn.net:8080 then http://localhost:3000/proxiedOCCIServer/-/
  app.all('/conf', function(req, res) {
    var target = querystring.parse(req._parsedUrl.query).proxyTarget;

    //if the proxyOptions does not exist yet, we create it
    if(!req.session.proxyOptions){
      req.session.proxyOptions = proxyOptions;
    }
    req.session.proxyOptions.target = target;

    req.session.proxyOptions.target = querystring.parse(req._parsedUrl.query).proxyTarget;
    console.log('updated proxyOptions via current session', req.session.proxyOptions);
    console.log('id of session: '+req.sessions.id);
    res.setHeader('Content-Type', 'application/javascript');
    res.end('{}');
  });
}

var isProduction = process.env.NODE_ENV === 'production';
console.log('env is prod =', isProduction);

if (isProduction) { // prod :
  var express = require('express');
  var http = require('http');
  var httpProxy = require('http-proxy');
  var proxy = new httpProxy.createProxyServer({secure: false});

  // Init express server
  var app = this.app = new express();

  app.use(express.static(__dirname + '/'));

  //we make a session for each new user
  app.use(session({
      secret: 'keyboard cat'
  }));

  app.all(proxyOptions.path, function (req, res, next) {
    proxyOptions.rewrite(req, proxyOptions);

    proxy.web(req, res, proxyOptions, function(err){
      var msg = 'cannot proxy to ' + proxyOptions.target + '('+ err.message + ')';
      console.log('proxy-error'+msg);<commit_msg>fix typo<commit_after>const querystring = require('querystring');
var session = require('express-session');

const conf = require('./conf.js');


///var host = 'occinterface.herokuapp.com'
var port = process.env.PORT || 3000;
var proxyDefaultTarget = conf.backendURL;

//we define the backendURL as a gloabl variable
// window.backendURL = proxyDefaultTarget;

var proxyOptions = {
  path : '/proxiedOCCIServer/**',
  target: proxyDefaultTarget,
  rewrite: function(req) {
    req.url = req.url.replace(new RegExp('^\/proxiedOCCIServer'), '');
  },
  changeOrigin: true
};

function setup(app) {
  // update the proxied target URL :
  // test using ex. http://localhost:3000/conf?proxyTarget=http://malmo.lizenn.net:8080 then http://localhost:3000/proxiedOCCIServer/-/
  app.all('/conf', function(req, res) {
    var target = querystring.parse(req._parsedUrl.query).proxyTarget;

    //if the proxyOptions does not exist yet, we create it
    if(!req.session.proxyOptions){
      req.session.proxyOptions = proxyOptions;
    }
    req.session.proxyOptions.target = target;

    req.session.proxyOptions.target = querystring.parse(req._parsedUrl.query).proxyTarget;
    console.log('updated proxyOptions via current session', req.session.proxyOptions);
    console.log('id of session: '+req.session.id);
    res.setHeader('Content-Type', 'application/javascript');
    res.end('{}');
  });
}

var isProduction = process.env.NODE_ENV === 'production';
console.log('env is prod =', isProduction);

if (isProduction) { // prod :
  var express = require('express');
  var http = require('http');
  var httpProxy = require('http-proxy');
  var proxy = new httpProxy.createProxyServer({secure: false});

  // Init express server
  var app = this.app = new express();

  app.use(express.static(__dirname + '/'));

  //we make a session for each new user
  app.use(session({
      secret: 'keyboard cat'
  }));

  app.all(proxyOptions.path, function (req, res, next) {
    proxyOptions.rewrite(req, proxyOptions);

    proxy.web(req, res, proxyOptions, function(err){
      var msg = 'cannot proxy to ' + proxyOptions.target + '('+ err.message + ')';
      console.log('proxy-error'+msg);
{'fraction_non_alphanumeric': 0.1535288725939505, 'fraction_numerical': 0.007332722273143905, 'mean_word_length': 3.982876712328767, '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': '1288942', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1331, 'n_words': 314}