<commit_before>/**
 * EzMaster entrypoint
 */

/*eslint global-require:"warn"*/
'use strict';

var cfg   = require('./lib/config.js');
var kuler = require('kuler');
var debug = require('debug')('ezmaster');

var express = require('express');
var app    = express();
var server = require('http').Server(app);
var io     = require('socket.io')(server);
var cors      = require('cors');
var basicAuth = require('basic-auth-connect');

var instances = require('./lib/instances.js');
var DAV       = require('jsDAV/lib/jsdav');

// load routes and middleware
app.use(cors()); // to allow ezmaster-front to call it from client side
app.use(basicAuth(process.env.EZMASTER_USER, process.env.EZMASTER_PASSWORD));
app.use(require('./middlewares/reverse-proxy.js'));
app.use(express.static('public'));
app.use('/-/v1/',          require('./routes/v1.js'));
app.use('/-/v1/config',    require('./routes/v1-config.js'));
app.use('/-/v1/app',       require('./routes/v1-app.js'));
app.use('/-/v1/hub',       require('./routes/v1-hub.js'));
app.use('/-/v1/instances', require('./routes/v1-instances.js'));

app.use(function (req, res, next) {

  if (req.url.search(/^\/wd--/) >= 0) {
    var instanceId = req.url.match('wd--([^/]+)')[1];

    instances.checkInstance(instanceId, function(err, container, data, manifest) {

      if (err) { return next(err); }

      var splittedName = data.Name.split('/');
      debug('url', req.url);
      DAV.mount({
        node: cfg.dataInstancesPath + '/' + splittedName[1] + '/data',
        mount: '/wd--' + instanceId,
        server: req.app,
        standalone: false
      }).exec(req, res);


    });

  }
  else {
    return next();
  }
  /*
  */
});<commit_msg>handle empty EZMASTER_USER and EZMASTER_PASSWORD<commit_after>/**
 * EzMaster entrypoint
 */

/*eslint global-require:"warn"*/
'use strict';

var cfg   = require('./lib/config.js');
var kuler = require('kuler');
var debug = require('debug')('ezmaster');

var express = require('express');
var app    = express();
var server = require('http').Server(app);
var io     = require('socket.io')(server);
var cors      = require('cors');
var basicAuth = require('basic-auth-connect');

var instances = require('./lib/instances.js');
var DAV       = require('jsDAV/lib/jsdav');


app.use(cors()); // to allow ezmaster-front to call it from client side

// to secure the API
if (process.env.EZMASTER_USER !== '' && process.env.EZMASTER_PASSWORD !== '') {
  app.use(basicAuth(process.env.EZMASTER_USER, process.env.EZMASTER_PASSWORD));  
}

// connect static ressources located in public folder
app.use(express.static('public'));

// connect the reverse proxy stuff (to be removed in ezmaster 4.0)
app.use(require('./middlewares/reverse-proxy.js'));

// connect the API routes
app.use('/-/v1/',          require('./routes/v1.js'));
app.use('/-/v1/config',    require('./routes/v1-config.js'));
app.use('/-/v1/app',       require('./routes/v1-app.js'));
app.use('/-/v1/hub',       require('./routes/v1-hub.js'));
app.use('/-/v1/instances', require('./routes/v1-instances.js'));

// connect the webdav stuff (to be removed in ezmaster 4.0)
app.use(function (req, res, next) {

  if (req.url.search(/^\/wd--/) >= 0) {
    var instanceId = req.url.match('wd--([^/]+)')[1];

    instances.checkInstance(instanceId, function(err, container, data, manifest) {

      if (err) { return next(err); }

      var splittedName = data.Name.split('/');
      debug('url', req.url);
      DAV.mount({
        node: cfg.dataInstancesPath + '/' + splittedName[1] + '/data',
        mount: '/wd--' + instanceId,
        server: req.app,
        standalone: false
      }).exec(req, res);


    });

  }
  else {
    return next();
  }
  /*
  */
});
{'fraction_non_alphanumeric': 0.2109795479009688, 'fraction_numerical': 0.008073196986006458, 'mean_word_length': 3.1670403587443947, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2091498', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1268, 'n_words': 257}