<commit_before>const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const compression = require('compression');
const session = require('express-session');
const mongoose = require('mongoose');
const cloudinary = require('cloudinary');

const configs = require('./config.js');

const schemas = require('./schemas.js');
let Home = schemas.Home;
let Area = schemas.Area;

const app = express();

// Middleware
app.use(morgan('dev'));
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
app.use(bodyParser.text({defaultCharset: 'utf-8'}));
app.use(compression());

// Database
mongoose.connect('mongodb://localhost/applehomes');

// Sessions
app.use(session({
  secret: 'apple homes',
  resave: false,
  saveUninitialized: true
}));

// Cloudinary
cloudinary.config(configs.cloudinary);

app.use(express.static(path.join(__dirname, '../client')));

// Middleware for route authentication
function isAuthenticated(req, res, next) {
  if (req.session.authenticated = true) {
    return next();
  }

  res.redirect('/login');
}

// Routes

// Route for testing purposes
app.get('/api/test', (req, res) => {
  cloudinary.api.resources(function(result) {
    res.send(result);
  },
    {
      type: 'upload',
      prefix: '50 Alice Street Unit C, Arcadia, CA 91006/'
    });
});

// Route for login
app.post('/api/login', (req, res) => {
  if (req.body.password === configs.SITE_PASSWORD) {
    req.session.authenticated = true;

    res.send({
      authenticated: true
    });
  } else {
    req.session.authenticated = false;
    
    res.send({
      authenticated: false
    });
  }
});<commit_msg>Change to make route auth middleware redirect to main page<commit_after>const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const compression = require('compression');
const session = require('express-session');
const mongoose = require('mongoose');
const cloudinary = require('cloudinary');

const configs = require('./config.js');

const schemas = require('./schemas.js');
let Home = schemas.Home;
let Area = schemas.Area;

const app = express();

// Middleware
app.use(morgan('dev'));
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
app.use(bodyParser.text({defaultCharset: 'utf-8'}));
app.use(compression());

// Database
mongoose.connect('mongodb://localhost/applehomes');

// Sessions
app.use(session({
  secret: 'apple homes',
  resave: false,
  saveUninitialized: true
}));

// Cloudinary
cloudinary.config(configs.cloudinary);

app.use(express.static(path.join(__dirname, '../client')));

// Middleware for route authentication
function isAuthenticated(req, res, next) {
  if (req.session.authenticated = true) {
    return next();
  }

  res.redirect('/');
}

// Routes

// Route for testing purposes
app.get('/api/test', (req, res) => {
  cloudinary.api.resources(function(result) {
    res.send(result);
  },
    {
      type: 'upload',
      prefix: '50 Alice Street Unit C, Arcadia, CA 91006/'
    });
});

// Route for login
app.post('/api/login', (req, res) => {
  if (req.body.password === configs.SITE_PASSWORD) {
    req.session.authenticated = true;

    res.send({
      authenticated: true
    });
  } else {
    req.session.authenticated = false;
    
    res.send({
      authenticated: false
    });
  }
});
{'fraction_non_alphanumeric': 0.17640385706182643, 'fraction_numerical': 0.006806579693703914, 'mean_word_length': 4.0968208092485545, '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': '3693535', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1127, 'n_words': 249}