<commit_before>import "babel-polyfill";
import Hapi = require('hapi');
import Io = require('socket.io');
import path = require('path');
import winston = require("winston");
import chalk = require('chalk');
import figlet = require('figlet');

import Api from "./api/Api";
import ProgramResource from "./api/resource/versioncontrol/ProgramResource";
import GitProgramStorage from "./versioncontrol/GitProgramStorage";
import modelRegistry from "./jsonapi/ModelSerializerRegistry";
import WorkingTreeFileResource from "./api/resource/versioncontrol/WorkingTreeFileResource";
import WorkingTreeDirectoryResource from "./api/resource/versioncontrol/WorkingTreeDirectoryResource";
import ProcessResource from "./api/resource/ProcessResource";
import SocketIoProcessAdapter from "./process/SocketIoProcessAdapter";
import NodeProcessManager from "./process/NodeProcessManager";
import BlobResource from "./api/resource/versioncontrol/BlobResource";
import TreeResource from "./api/resource/versioncontrol/TreeResource";
import VersionResource from "./api/resource/versioncontrol/VersionResource";

// Return external module as the file is outside of the
// TypeScript compile output
// tslint:disable-next-line
let serverConfig = require('../../../config/server.config');


console.log(chalk.green(figlet.textSync('Hedgehog IDE')));

/**
 * Logger setup
 * We use one global logger instance for logging
 */
winston.configure({
    transports: [
        new (winston.transports.Console)({
            colorize: true,
            prettyPrint: true
        })
    ]
});
winston.level = 'debug';


/**
 * Server setup
 */
// Create a server with a host and port
const server = new Hapi.Server({
    connections: {
        routes: {
            files: {
                relativeTo: path.join(__dirname, '..')
            }
        }
    }
});

server.connection(serverConfig.connection);

/**
 * API setup
 */
let programStorage = new GitProgramStorage(serverConfig.programStorageDirectory);
let processManager = new NodeProcessManager(
    serverConfig.process.temporaryStorageDirectory,
    serverConfig.process.pythonPath,
    programStorage
);

let hedgehogApi = new Api(server, '/api');
hedgehogApi.registerEndpoint(new ProgramResource(programStorage, modelRegistry));
hedgehogApi.registerEndpoint(new WorkingTreeFileResource(programStorage, modelRegistry));
hedgehogApi.registerEndpoint(new WorkingTreeDirectoryResource(programStorage, modelRegistry));
hedgehogApi.registerEndpoint(new BlobResource(programStorage, modelRegistry));
hedgehogApi.registerEndpoint(new TreeResource(programStorage, modelRegistry));
hedgehogApi.registerEndpoint(new VersionResource(programStorage, modelRegistry));
hedgehogApi.registerEndpoint(new ProcessResource(processManager, modelRegistry));

/**
 * Socket.io setup
 */
let io = Io(server.listener);
new SocketIoProcessAdapter(processManager, io);

// tslint:disable-next-line
server.register(require('inert'));

/**
 * Static resources (Angular webapp)
 */
server.route({
    method: 'GET',
    path: '/node_modules/{param*}',
    handler: {
        directory: {
            path: '../../node_modules',
            redirectToSlash: true
        }
    }
});

if (serverConfig.environment === 'production') {
    server.route({
        method: 'GET',
        path: '/assets/{param*}',
        handler: {
            directory: {
                path: 'client/assets',
                redirectToSlash: true
            }
        }
    });

    server.route({
        method: 'GET',
        path: '/{param*}',
        handler: {
            directory: {
                path: '../dist',
                redirectToSlash: true,
                index: true
            }
        }
    });
} else {
    server.route({
        method: 'GET',
        path: '/common/{param*}',
        handler: {
            directory: {
                path: 'common',
                redirectToSlash: true
            }
        }
    });

    server.route({
        method: 'GET',
        path: '/{param*}',
        handler: {
            directory: {
                path: 'client',
                redirectToSlash: true,
                index: true
            }
        }
    });
}

/**
 * Handler for 404 which also serves the Angular webapp
 * (This enables routing within the real path section)
 */
server.ext('onPreResponse', (request, reply) => {<commit_msg>fix production index redirect<commit_after>import "babel-polyfill";
import Hapi = require('hapi');
import Io = require('socket.io');
import path = require('path');
import winston = require("winston");
import chalk = require('chalk');
import figlet = require('figlet');

import Api from "./api/Api";
import ProgramResource from "./api/resource/versioncontrol/ProgramResource";
import GitProgramStorage from "./versioncontrol/GitProgramStorage";
import modelRegistry from "./jsonapi/ModelSerializerRegistry";
import WorkingTreeFileResource from "./api/resource/versioncontrol/WorkingTreeFileResource";
import WorkingTreeDirectoryResource from "./api/resource/versioncontrol/WorkingTreeDirectoryResource";
import ProcessResource from "./api/resource/ProcessResource";
import SocketIoProcessAdapter from "./process/SocketIoProcessAdapter";
import NodeProcessManager from "./process/NodeProcessManager";
import BlobResource from "./api/resource/versioncontrol/BlobResource";
import TreeResource from "./api/resource/versioncontrol/TreeResource";
import VersionResource from "./api/resource/versioncontrol/VersionResource";

// Return external module as the file is outside of the
// TypeScript compile output
// tslint:disable-next-line
let serverConfig = require('../../../config/server.config');


console.log(chalk.green(figlet.textSync('Hedgehog IDE')));

/**
 * Logger setup
 * We use one global logger instance for logging
 */
winston.configure({
    transports: [
        new (winston.transports.Console)({
            colorize: true,
            prettyPrint: true
        })
    ]
});
winston.level = 'debug';


/**
 * Server setup
 */
// Create a server with a host and port
const server = new Hapi.Server({
    connections: {
        routes: {
            files: {
                relativeTo: path.join(__dirname, '../..')
            }
        }
    }
});

server.connection(serverConfig.connection);

/**
 * API setup
 */
let programStorage = new GitProgramStorage(serverConfig.programStorageDirectory);
let processManager = new NodeProcessManager(
    serverConfig.process.temporaryStorageDirectory,
    serverConfig.process.pythonPath,
    programStorage
);

let hedgehogApi = new Api(server, '/api');
hedgehogApi.registerEndpoint(new ProgramResource(programStorage, modelRegistry));
hedgehogApi.registerEndpoint(new WorkingTreeFileResource(programStorage, modelRegistry));
hedgehogApi.registerEndpoint(new WorkingTreeDirectoryResource(programStorage, modelRegistry));
hedgehogApi.registerEndpoint(new BlobResource(programStorage, modelRegistry));
hedgehogApi.registerEndpoint(new TreeResource(programStorage, modelRegistry));
hedgehogApi.registerEndpoint(new VersionResource(programStorage, modelRegistry));
hedgehogApi.registerEndpoint(new ProcessResource(processManager, modelRegistry));

/**
 * Socket.io setup
 */
let io = Io(server.listener);
new SocketIoProcessAdapter(processManager, io);

// tslint:disable-next-line
server.register(require('inert'));

/**
 * Static resources (Angular webapp)
 */
server.route({
    method: 'GET',
    path: '/node_modules/{param*}',
    handler: {
        directory: {
            path: '../node_modules',
            redirectToSlash: true
        }
    }
});

if (serverConfig.environment === 'production') {
    server.route({
        method: 'GET',
        path: '/assets/{param*}',
        handler: {
            directory: {
                path: 'src/client/assets',
                redirectToSlash: true
            }
        }
    });

    server.route({
        method: 'GET',
        path: '/{param*}',
        handler: {
            directory: {
                path: 'dist',
                redirectToSlash: true,
                index: true
            }
        }
    });
} else {
    server.route({
        method: 'GET',
        path: '/common/{param*}',
        handler: {
            directory: {
                path: 'src/common',
                redirectToSlash: true
            }
        }
    });

    server.route({
        method: 'GET',
        path: '/{param*}',
        handler: {
            directory: {
                path: 'src/client',
                redirectToSlash: true,
                index: true
            }
        }
    });
}

/**
 * Handler for 404 which also serves the Angular webapp
 * (This enables routing within the real path section)
 */
server.ext('onPreResponse', (request, reply) => {
{'fraction_non_alphanumeric': 0.12461485792536803, 'fraction_numerical': 0.0006846970215679561, 'mean_word_length': 2.9265232974910393, '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': '2090175', 'n_tokens_mistral': 2354, 'n_tokens_neox': 2276, 'n_words': 529}