<commit_before>'use strict'

const express = require('express')
const logger = require('morgan')
const session = require('express-session')
const MongoStore = require('connect-mongo')(session)
const config = require('config')
const routes = require('./routes')

// Loaded right here to force schema validation at boot time
const chalk = require('chalk')
const { getFrontSchema, getMongooseSchema } = require('./lib/schemas')
const { getLayout } = require('./lib/layouts')
let errors = []
Object.keys(config.collections).forEach(name => {
	try {
		getMongooseSchema(name)
		getLayout(name)
		getFrontSchema(name)
	} catch (e) {
		process.stderr.write(`\n\n${chalk.bold.red(`Fatal error in schema "${name}"`)}:\n${chalk.red(e.message)}\n\n`)
		errors.push(name)
	}
})
if (errors.length > 0) {
	process.stderr.write(`\n\n${chalk.bold.red(`Fatal error in following schemas: ${errors.join(', ')}`)}\n${chalk.red('Check errors above')}\n\n`)
	process.exit(1)
}


const app = module.exports = express()

if (config.log.format) {
	app.use(logger(config.log.format))
}

app.use(session({
	secret: config.session.secret,
	resave: true,
	saveUninitialized: false,
	store: new MongoStore({
		url: config.mongo.url,
		ttl: config.session.ttl
	})
}))

app.use('/', routes.index)
app.use('/auth', routes.auth)
app.use('/people', routes.people)
app.use('/organizations', routes.organizations)
app.use('/activities', routes.activities)
app.use('/schemas', routes.schemas)
app.use('/layouts', routes.layouts)
app.use('/enums', routes.enums)

// Error handlers
app.use(routes.errors.notFound)
app.use(routes.errors.serverError(app.get('env') === 'development'))
<commit_msg>feat(server): more info about what crashed in schema validation<commit_after>'use strict'

const express = require('express')
const logger = require('morgan')
const session = require('express-session')
const MongoStore = require('connect-mongo')(session)
const config = require('config')
const routes = require('./routes')

// Loaded right here to force schema validation at boot time
const chalk = require('chalk')
const { getFrontSchema, getMongooseSchema } = require('./lib/schemas')
const { getLayout } = require('./lib/layouts')
let errors = []
Object.keys(config.collections).forEach(name => {
	try {
		getMongooseSchema(name)
	} catch (e) {
		process.stderr.write(`\n\n${chalk.bold.red(`Fatal error in schema (mongoose) "${name}"`)}:\n${chalk.red(e.message)}\n\n`)
		errors.push(name)
	}
	try {
		getFrontSchema(name)
	} catch (e) {
		process.stderr.write(`\n\n${chalk.bold.red(`Fatal error in schema (front) "${name}"`)}:\n${chalk.red(e.message)}\n\n`)
		errors.push(name)
	}
	try {
		getLayout(name)
	} catch (e) {
		process.stderr.write(`\n\n${chalk.bold.red(`Fatal error in layout "${name}"`)}:\n${chalk.red(e.message)}\n\n`)
		errors.push(name)
	}
})
if (errors.length > 0) {
	process.stderr.write(`\n\n${chalk.bold.red(`Fatal error in following schemas: ${errors.join(', ')}`)}\n${chalk.red('Check errors above')}\n\n`)
	process.exit(1)
}


const app = module.exports = express()

if (config.log.format) {
	app.use(logger(config.log.format))
}

app.use(session({
	secret: config.session.secret,
	resave: true,
	saveUninitialized: false,
	store: new MongoStore({
		url: config.mongo.url,
		ttl: config.session.ttl
	})
}))

app.use('/', routes.index)
app.use('/auth', routes.auth)
app.use('/people', routes.people)
app.use('/organizations', routes.organizations)
app.use('/activities', routes.activities)
app.use('/schemas', routes.schemas)
app.use('/layouts', routes.layouts)
app.use('/enums', routes.enums)

// Error handlers
app.use(routes.errors.notFound)
app.use(routes.errors.serverError(app.get('env') === 'development'))

{'fraction_non_alphanumeric': 0.1929634641407307, 'fraction_numerical': 0.0010825439783491205, 'mean_word_length': 5.149750415973378, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1592846', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1277, 'n_words': 248}