<commit_before>/**
 * Express API and web server
 */

const config = require('./config')();

const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const logger = require('morgan');
const swaggerUiDist = require('swagger-ui-dist');
const swaggerJSDoc = require('swagger-jsdoc');

const version = require('../../package.json').version;
const api = require('./api');
const alphaRedirectMiddleware = require('./alphaRedirectMiddleware');

function getVersion() {
    return version.substring(0, version.indexOf('-'));
}

function setupLogging(app) {
    if (config.debug) {
        app.use(logger('dev'));
    }
    else {
        app.use(logger('common', {
            skip: (req, res) => res.statusCode < 400,
            stream: process.stderr
        }));

        app.use(logger('common', {
            skip: (req, res) => res.statusCode >= 400,
            stream: process.stdout
        }));
    }
}

function setupStaticViews(app) {
    // set up template engine
    app.set('views', path.join(__dirname, '../../web/src/templates'));
    app.set('view engine', 'ejs');
}

function setupDataInput(app) {
    // accept REST data parameters
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: true }));
}

function setupApiDocs(app) {<commit_msg>Use forwarded IP address when running behind a proxy<commit_after>/**
 * Express API and web server
 */

const config = require('./config')();

const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const logger = require('morgan');
const swaggerUiDist = require('swagger-ui-dist');
const swaggerJSDoc = require('swagger-jsdoc');

const version = require('../../package.json').version;
const api = require('./api');
const alphaRedirectMiddleware = require('./alphaRedirectMiddleware');

function getVersion() {
    return version.substring(0, version.indexOf('-'));
}

function setupLogging(app) {
    if (config.debug) {
        app.use(logger('dev'));
    }
    else {
        logger.token('remote-addr', req => req.headers['x-real-ip'] ||
            req.headers['x-forwarded-for'] || req.connection.remoteAddress);

        app.use(logger('common', {
            skip: (req, res) => res.statusCode < 400,
            stream: process.stderr
        }));

        app.use(logger('common', {
            skip: (req, res) => res.statusCode >= 400,
            stream: process.stdout
        }));
    }
}

function setupStaticViews(app) {
    // set up template engine
    app.set('views', path.join(__dirname, '../../web/src/templates'));
    app.set('view engine', 'ejs');
}

function setupDataInput(app) {
    // accept REST data parameters
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: true }));
}

function setupApiDocs(app) {
{'fraction_non_alphanumeric': 0.17229254571026723, 'fraction_numerical': 0.004922644163150493, 'mean_word_length': 3.196165191740413, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '6840483', 'n_tokens_mistral': 835, 'n_tokens_neox': 828, 'n_words': 187}