<commit_before>/* eslint-disable class-methods-use-this */

const baiji = require('baiji');
const path = require('path');

const baijiLogger = require('../../index');

const { accessLogger, error, info, debug } = baijiLogger({
  appkey: 'nereusService',
  baseDir: path.join(__dirname, './logs'),
});

const infoLogger = info();
const errorLogger = error();
const debugLogger = debug();

const app = baiji('test');

class UsersCtrl extends baiji.Controller {
  constructor() {
    super();
    // Use before actions
    this.beforeAction('signInRequired');
  }

  initConfig() {
    return {
      search: {
        description: 'Search users...',
        route: { path: '/', verb: 'get' },
      },
    };
  }

  signInRequired(ctx, next) {
    const token = ctx.req.get('authorization');
    debugLogger.info(token);
    debugLogger.error(token);
    if (token) {
      return next();
    }
    const err = new Error('Unauthorized');
    errorLogger.error(err);
    ctx.status(401);
    return ctx.respond({ err });
  }

  search(ctx, next) {
    return ctx.respond([{ username: 'bamaying', gender: 1 }], next);
  }
}

app.use(accessLogger());

// Use controller
app.use(UsersCtrl);

// Start app and listen on port 3000
app.listen(3000, () => infoLogger.info('Port : 3000'));<commit_msg>docs(doc): update test case appkey<commit_after>/* eslint-disable class-methods-use-this */

const baiji = require('baiji');
const path = require('path');

const baijiLogger = require('../../index');

const { accessLogger, error, info, debug } = baijiLogger({
  appkey: 'serviceName',
  baseDir: path.join(__dirname, './logs'),
});

const infoLogger = info();
const errorLogger = error();
const debugLogger = debug();

const app = baiji('serviceName');

class UsersCtrl extends baiji.Controller {
  constructor() {
    super();
    // Use before actions
    this.beforeAction('signInRequired');
  }

  initConfig() {
    return {
      search: {
        description: 'Search users...',
        route: { path: '/', verb: 'get' },
      },
    };
  }

  signInRequired(ctx, next) {
    const token = ctx.req.get('authorization');
    debugLogger.info(token);
    debugLogger.error(token);
    if (token) {
      return next();
    }
    const err = new Error('Unauthorized');
    errorLogger.error(err);
    ctx.status(401);
    return ctx.respond({ err });
  }

  search(ctx, next) {
    return ctx.respond([{ username: 'serviceName', gender: 1 }], next);
  }
}

app.use(accessLogger());

// Use controller
app.use(UsersCtrl);

// Start app and listen on port 3000
app.listen(3000, () => infoLogger.info('Port : 3000'));
{'fraction_non_alphanumeric': 0.17133001149865848, 'fraction_numerical': 0.012265235722499043, 'mean_word_length': 3.271685761047463, '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': '2085588', 'n_tokens_mistral': 844, 'n_tokens_neox': 808, 'n_words': 199}