<commit_before>// Load environment variables from .env, .env.local, etc. This explicit call
// into `@next/env` allows using environment variables before next() is called.
// More info: https://nextjs.org/docs/basic-features/environment-variables
const { loadEnvConfig } = require('@next/env');

const projectDir = process.cwd();

loadEnvConfig(
  projectDir,
  process.env.NODE_ENV === 'development',
);

const express = require('express');
const next = require('next');
const session = require('express-session');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const basicAuth = require('basic-auth');
const serveStatic = require('serve-static');
const redis = require('redis');
const RedisStore = require('connect-redis')(session);
const path = require('path');

const port = process.env.PORT || 3000;

// We need next in prod mode for production and testing environments
// Otherwise, in test, next will compile crap on the fly and timeout tests
const prod = process.env.NODE_ENV !== 'development';

// Next app creation
const app = next({ dev: !prod });
const handle = app.getRequestHandler();

// Express app creation
const server = express();

// http://expressjs.com/en/advanced/best-practice-security.html#at-a-minimum-disable-x-powered-by-header
server.disable('x-powered-by');

function checkBasicAuth(credentials) {
  return function authMiddleware(req, res, nextAction) {
    if (!/(AddSearchBot)|(HeadlessChrome)/.test(req.headers['user-agent'])) {
      const user = basicAuth(req);
      let authorized = false;
      if (user && (user.name === credentials.name && user.pass === <PASSWORD>)) {
        authorized = true;
      }

      if (!authorized) {
        res.set('WWW-Authenticate', 'Basic realm=Authorization Required');
        return res.sendStatus(401);
      }
    }
    return nextAction();
  };
}

// Configuring session and cookie options
const sessionOptions = {
  secret: process.env.SECRET || 'keyboard cat',
  resave: false,
  saveUninitialized: true,
};
<commit_msg>skips internal API calls from basic-auth<commit_after>// Load environment variables from .env, .env.local, etc. This explicit call
// into `@next/env` allows using environment variables before next() is called.
// More info: https://nextjs.org/docs/basic-features/environment-variables
const { loadEnvConfig } = require('@next/env');

const projectDir = process.cwd();

loadEnvConfig(
  projectDir,
  process.env.NODE_ENV === 'development',
);

const express = require('express');
const next = require('next');
const session = require('express-session');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const basicAuth = require('basic-auth');
const serveStatic = require('serve-static');
const redis = require('redis');
const RedisStore = require('connect-redis')(session);
const path = require('path');

const port = process.env.PORT || 3000;

// We need next in prod mode for production and testing environments
// Otherwise, in test, next will compile crap on the fly and timeout tests
const prod = process.env.NODE_ENV !== 'development';

// Next app creation
const app = next({ dev: !prod });
const handle = app.getRequestHandler();

// Express app creation
const server = express();

// http://expressjs.com/en/advanced/best-practice-security.html#at-a-minimum-disable-x-powered-by-header
server.disable('x-powered-by');

function checkBasicAuth(credentials) {
  return function authMiddleware(req, res, nextAction) {
    if (
      !/(AddSearchBot)|(HeadlessChrome)/.test(req.headers['user-agent'])
      // unblocks requests from the internal API
      && !req.url.startsWith('/api')
    ) {
      const user = basicAuth(req);
      let authorized = false;
      if (user && (user.name === credentials.name && user.pass === <PASSWORD>)) {
        authorized = true;
      }

      if (!authorized) {
        res.set('WWW-Authenticate', 'Basic realm=Authorization Required');
        return res.sendStatus(401);
      }
    }
    return nextAction();
  };
}

// Configuring session and cookie options
const sessionOptions = {
  secret: process.env.SECRET || 'keyboard cat',
  resave: false,
  saveUninitialized: true,
};

{'fraction_non_alphanumeric': 0.14488973203699312, 'fraction_numerical': 0.003319895660422101, 'mean_word_length': 4.088057901085645, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6133008', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1198, 'n_words': 338}