<commit_before>'use strict';

import Koa from 'koa';
import json from 'koa-json';
import Debug from 'debug';

import * as User from './route/user';

const app = new Koa();
const debug = Debug('koa-play:root');

// Register middleware to handle json
app.use(json());

app.use(async(ctx, next) => {
    try {
        await next();
    } catch (error) {
        debug('error occurred: %j', error);
        
        if (error.isBoom) {
            ctx.body = error.output.payload;
            ctx.status = error.output.statusCode;

            return;
        }
        throw error;
    }
});

// Registers routes and allowed method middlewares for different routes
app.use(User.Routes);
app.use(User.AllowedMethod);

debug('server started at port: %d', 4000);<commit_msg>Add logger middleware<commit_after>'use strict';

import Koa from 'koa';
import Debug from 'debug';

import jsonMiddleware from 'koa-json';
import loggerMiddleware from 'koa-bunyan-logger';

import * as User from './route/user';

const app = new Koa();
const debug = Debug('koa-play:root');

// Register middleware
app.use(jsonMiddleware());
app.use(loggerMiddleware());

app.use(async (ctx, next) => {
    ctx.log.info(`request from ${ctx.request.ip} to ${ctx.path}`);
    await next();
});

app.use(async(ctx, next) => {
    try {
        await next();
    } catch (error) {
        ctx.log.error(error);

        if (error.isBoom) {
            ctx.body = error.output.payload;
            ctx.status = error.output.statusCode;

            return;
        } else {
            // TODO: Handle error that are not instance of `boom`
        }
        throw error;
    }
});

// Registers routes and allowed method middleware for different routes
// FIXME: This should be simplified
app.use(User.Routes);
app.use(User.AllowedMethod);

debug('server started at port: %d', 4000);
{'fraction_non_alphanumeric': 0.14301191765980498, 'fraction_numerical': 0.004333694474539545, 'mean_word_length': 2.746450304259635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '6968923', 'n_tokens_mistral': 578, 'n_tokens_neox': 576, 'n_words': 163}