<commit_before>/**
 * Copyright 2017 IBM Corp. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* jslint node: true, esversion: 6 */
'use strict';

const debug = require('debug')('wchbotserver:app');

const express = require('express');
const bodyParser  = require('body-parser');
const syncRoutes = require('./routes/sync');
const path = require('path');

const appEnv = require('./lib/env');
const bots = require('./lib/bots');

// create a new express server
const app = express();

const logErr = (err) => {debug(err); throw err;}
const logTrace = (value) => {debug(value); return value;}

debug(
`Starting Server...
Environment: ${(appEnv.isLocal) ? "local" : "bluemix"}`
);

app.set('appEnv', appEnv);

app.use(bodyParser.json());

bots(app);

app.use('/sync', syncRoutes);

/// catch 404 and forward to error handler
app.use(function(req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
});

/** Error Handlers */

let errorHandler;
if (app.get('appEnv').isLocal === true) {
  // Error Handler: Development 
  errorHandler = function(err, req, res, next) {
      res.status(err.status || 500);
      res.send({
          message: err.message,
          error: err
      });
  };
} else {
  // Error Handler: Production
  errorHandler = function(err, req, res, next) {
      res.status(err.status || 500);
      res.send({
          message: err.message,
          error: {}
      });
  };
}

app.use('/', errorHandler);

module.exports = app;<commit_msg>Add debug and urlencoder parser.<commit_after>/**
 * Copyright 2017 IBM Corp. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* jslint node: true, esversion: 6 */
'use strict';

const debug = require('debug')('wchbotserver:app');

const express = require('express');
const bodyParser  = require('body-parser');
const syncRoutes = require('./routes/sync');
const path = require('path');

const appEnv = require('./lib/env');
const bots = require('./lib/bots');

// create a new express server
const app = express();

const logErr = (err) => {debug(err); throw err;}
const logTrace = (value) => {debug(value); return value;}

debug(
`Starting Server...
Environment: ${(appEnv.isLocal) ? "local" : "bluemix"}`
);

app.set('appEnv', appEnv);

app.use(bodyParser.json());
app.use(bodyParser.urlencoded());

debug('Configured bots');
bots(app);

debug('Configured sync');
app.use('/sync', syncRoutes);

debug('Configured error handling');
/// catch 404 and forward to error handler
app.use(function(req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
});

/** Error Handlers */

let errorHandler;
if (app.get('appEnv').isLocal === true) {
  // Error Handler: Development 
  errorHandler = function(err, req, res, next) {
    debug('Error handler %o', err);
    res.status(err.status || 500);
    res.send({
        message: err.message,
        error: err
    });
  };
} else {
  // Error Handler: Production
  errorHandler = function(err, req, res, next) {
    debug('Error handler %o', err);
    res.status(err.status || 500);
    res.send({
        message: err.message,
        error: {}
    });
  };
}

app.use('/', errorHandler);

module.exports = app;
{'fraction_non_alphanumeric': 0.15155774185992035, 'fraction_numerical': 0.009838369641602248, 'mean_word_length': 3.5522388059701493, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '383664', 'n_tokens_mistral': 1316, 'n_tokens_neox': 1272, 'n_words': 431}