<commit_before>// PYRAMID
// Web module

const path = require("path");
const bodyParser = require("body-parser");

const config = require("../config");
const constants = require("./constants");
const log = require("./log");
const util = require("./util");

module.exports = function(main, io) {

	// Prerequisites
	const express  = require("express");
	//const favicon  = require("serve-favicon");
	const partials = require("express-partials");
	const fs       = require("fs");

	// The web app
	var app = express();
	app.set("views", path.join(__dirname, "..", "views"));
	app.set("view engine", "ejs");
	//app.use(favicon());
	app.use(bodyParser.urlencoded({ extended: "qs" }));
	app.use(express.static(path.join(__dirname, "..", "public")));
	app.use(partials());

	// Routes
	require("./routes")(app, main);

	// Fallback: 404 error
	app.use(function(req, res, next) {
		var err = new Error("Not Found");
		err.status = 404;
		next(err);
	});

	// --------------------------------------------------------
	// Error handlers

	// Development error handler
	// (Will print stacktrace)
	if (app.get("env") === "development") {
		app.use(function(err, req, res, next) {
			res.status(err.status || 500);
			res.render("error", {
				message: err.message,
				error: err
			});
		});
	}

	// Production error handler
	// (No stacktraces leaked to user)
	app.use(function(err, req, res, next) {
		res.status(err.status || 500);
		res.render("error", {
			message: err.message,
			error: {}
		});
	});

	// --------------------------------------------------------
	// Server
	// (HTTPS if specified)

	var server;

	if(
		typeof config.sslKeyPath == "string" && config.sslKeyPath != "" &&
		typeof config.sslCertPath == "string" && config.sslCertPath != ""
	){
		// Secure HTTPS server
		var https = require("https")
		server = https.createServer({
			key: fs.readFileSync(path.join(__dirname, config.sslKeyPath)),
			cert: fs.readFileSync(path.join(__dirname, config.sslCertPath))
		}, app).listen(config.webPort, undefined, undefined, function(){
			console.log("Listening securely on port %d", server.address().port);
		});
	} else {
		// Plain HTTP server
		server = app.listen(config.webPort, function() {
			console.log("Listening on port %d", server.address().port);
		});
	}

	app.server = server;
	io.setServer(app.server);

	return {<commit_msg>Assume server key and cert paths to be relative to root folder<commit_after>// PYRAMID
// Web module

const path = require("path");
const bodyParser = require("body-parser");

const config = require("../config");
const constants = require("./constants");
const log = require("./log");
const util = require("./util");

module.exports = function(main, io) {

	// Prerequisites
	const express  = require("express");
	//const favicon  = require("serve-favicon");
	const partials = require("express-partials");
	const fs       = require("fs");

	// The web app
	var app = express();
	app.set("views", path.join(__dirname, "..", "views"));
	app.set("view engine", "ejs");
	//app.use(favicon());
	app.use(bodyParser.urlencoded({ extended: "qs" }));
	app.use(express.static(path.join(__dirname, "..", "public")));
	app.use(partials());

	// Routes
	require("./routes")(app, main);

	// Fallback: 404 error
	app.use(function(req, res, next) {
		var err = new Error("Not Found");
		err.status = 404;
		next(err);
	});

	// --------------------------------------------------------
	// Error handlers

	// Development error handler
	// (Will print stacktrace)
	if (app.get("env") === "development") {
		app.use(function(err, req, res, next) {
			res.status(err.status || 500);
			res.render("error", {
				message: err.message,
				error: err
			});
		});
	}

	// Production error handler
	// (No stacktraces leaked to user)
	app.use(function(err, req, res, next) {
		res.status(err.status || 500);
		res.render("error", {
			message: err.message,
			error: {}
		});
	});

	// --------------------------------------------------------
	// Server
	// (HTTPS if specified)

	var server;

	if(
		typeof config.sslKeyPath == "string" && config.sslKeyPath != "" &&
		typeof config.sslCertPath == "string" && config.sslCertPath != ""
	){
		// Secure HTTPS server
		var https = require("https")
		server = https.createServer({
			key: fs.readFileSync(path.join(__dirname, "..", config.sslKeyPath)),
			cert: fs.readFileSync(path.join(__dirname, "..", config.sslCertPath))
		}, app).listen(config.webPort, undefined, undefined, function(){
			console.log("Listening securely on port %d", server.address().port);
		});
	} else {
		// Plain HTTP server
		server = app.listen(config.webPort, function() {
			console.log("Listening on port %d", server.address().port);
		});
	}

	app.server = server;
	io.setServer(app.server);

	return {
{'fraction_non_alphanumeric': 0.2291710388247639, 'fraction_numerical': 0.005036726128016789, 'mean_word_length': 2.9716666666666667, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6666444', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1505, 'n_words': 349}