<commit_before>const compression = require('compression');
const serveStatic = require('serve-static');
const bodyParser = require('body-parser');
const path = require('path');
const user = require('./user');
const github = require('./github');
const pdf = require('./pdf');
const pandoc = require('./pandoc');

const resolvePath = pathToResolve => path.join(__dirname, '..', pathToResolve);

module.exports = (app, serveV4) => {
  // Use gzip compression
  if (process.env.NODE_ENV === 'production') {
    app.all('*', (req, res, next) => {
      // Force HTTPS on stackedit.io
      if (req.headers.host === 'stackedit.io' && !req.secure && req.headers['x-forwarded-proto'] !== 'https') {
        res.redirect(`https://stackedit.io${req.url}`);
        return;
      }
      // Enable CORS for fonts
      if (/\.(eot|ttf|woff|svg)$/.test(req.url)) {
        res.header('Access-Control-Allow-Origin', '*');
      }
      next();
    });

    app.use(compression());
  }

  // Parse body mostly for PayPal IPN
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({
    extended: false,
  }));

  app.get('/oauth2/githubToken', github.githubToken);
  app.get('/userInfo', user.userInfo);
  app.post('/paypalIpn', user.paypalIpn);
  app.post('/pdfExport', pdf.generate);
  app.post('/pandocExport', pandoc.generate);

  if (serveV4) {
    /* eslint-disable global-require, import/no-unresolved */
    app.post('/sshPublish', require('../stackedit_v4/app/ssh').publish);
    app.post('/picasaImportImg', require('../stackedit_v4/app/picasa').importImg);
    app.get('/downloadImport', require('../stackedit_v4/app/download').importPublic);
    /* eslint-enable global-require, import/no-unresolved */
  }

  // Serve callback.html in /app
  app.get('/oauth2/callback', (req, res) => res.sendFile(resolvePath('static/oauth2/callback.html')));

  // Serve static resources
  if (process.env.NODE_ENV === 'production') {
    if (serveV4) {
      // Serve landing.html in /
      app.get('/', (req, res) => res.sendFile(resolvePath('stackedit_v4/views/landing.html')));
      // Serve editor.html in /viewer<commit_msg>Use body parser only for PayPal IPN<commit_after>const compression = require('compression');
const serveStatic = require('serve-static');
const bodyParser = require('body-parser');
const path = require('path');
const user = require('./user');
const github = require('./github');
const pdf = require('./pdf');
const pandoc = require('./pandoc');

const resolvePath = pathToResolve => path.join(__dirname, '..', pathToResolve);

module.exports = (app, serveV4) => {
  // Use gzip compression
  if (process.env.NODE_ENV === 'production') {
    app.all('*', (req, res, next) => {
      // Force HTTPS on stackedit.io
      if (req.headers.host === 'stackedit.io' && !req.secure && req.headers['x-forwarded-proto'] !== 'https') {
        res.redirect(`https://stackedit.io${req.url}`);
        return;
      }
      // Enable CORS for fonts
      if (/\.(eot|ttf|woff|svg)$/.test(req.url)) {
        res.header('Access-Control-Allow-Origin', '*');
      }
      next();
    });

    app.use(compression());
  }

  app.get('/oauth2/githubToken', github.githubToken);
  app.get('/userInfo', user.userInfo);
  app.post('/pdfExport', pdf.generate);
  app.post('/pandocExport', pandoc.generate);
  app.post('/paypalIpn', bodyParser.urlencoded({
    extended: false,
  }), user.paypalIpn);

  if (serveV4) {
    /* eslint-disable global-require, import/no-unresolved */
    app.post('/sshPublish', require('../stackedit_v4/app/ssh').publish);
    app.post('/picasaImportImg', require('../stackedit_v4/app/picasa').importImg);
    app.get('/downloadImport', require('../stackedit_v4/app/download').importPublic);
    /* eslint-enable global-require, import/no-unresolved */
  }

  // Serve callback.html in /app
  app.get('/oauth2/callback', (req, res) => res.sendFile(resolvePath('static/oauth2/callback.html')));

  // Serve static resources
  if (process.env.NODE_ENV === 'production') {
    if (serveV4) {
      // Serve landing.html in /
      app.get('/', (req, res) => res.sendFile(resolvePath('stackedit_v4/views/landing.html')));
      // Serve editor.html in /viewer
{'fraction_non_alphanumeric': 0.1963688485427616, 'fraction_numerical': 0.004777830864787387, 'mean_word_length': 3.4685165421558164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5782948', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1355, 'n_words': 246}