<commit_before>// *** main dependencies *** //
//require('dotenv').config();
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var swig = require('swig');
var cookieSession = require('cookie-session');
var queries = require("../../queries2");
var Promise = require('bluebird');
var passport = require('passport');
var knex = require('../../db/knex');
var GoogleStrategy = require( 'passport-google-oauth2' ).Strategy;
if ( !process.env.NODE_ENV ) { require('dotenv').config();}



// *** routes *** //
var routes = require('./routes/index.js');
var authRoutes = require('./routes/auth.js');
var userRoutes = require('./routes/users.js');
var adminRoutes = require('./routes/admin.js');
var cultureRoutes = require('./routes/index.js');



// *** express instance *** //
var app = express();


// *** view engine *** //
var swig = new swig.Swig();
app.engine('html', swig.renderFile);
app.set('view engine', 'html');


// *** static directory *** //
app.set('views', path.join(__dirname, 'views'));


// *** config middleware *** //
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(cookieSession({
  name: 'google-oauth-session-example',
  keys: [process.env.COOKIE_KEY1, process.env.COOKIE_KEY2]
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(express.static(path.join(__dirname, '../client')));
app.use(express.static(path.join(__dirname, '../client/image')));

// *** google auth *** //
passport.use(new GoogleStrategy({
    clientID:     process.env.GOOGLE_CLIENT_ID,
    clientSecret: process.env.GOOGLE_CLIENT_SECRET,<commit_msg>protected user routes via middlewar in app.js<commit_after>// *** main dependencies *** //
//require('dotenv').config();
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var swig = require('swig');
var cookieSession = require('cookie-session');
var queries = require("../../queries2");
var Promise = require('bluebird');
var passport = require('passport');
var knex = require('../../db/knex');
var GoogleStrategy = require( 'passport-google-oauth2' ).Strategy;
if ( !process.env.NODE_ENV ) { require('dotenv').config();}



// *** routes *** //
var routes = require('./routes/index.js');
var authRoutes = require('./routes/auth.js');
var userRoutes = require('./routes/users.js');
var adminRoutes = require('./routes/admin.js');
var cultureRoutes = require('./routes/index.js');



// *** express instance *** //
var app = express();


// *** view engine *** //
var swig = new swig.Swig();
app.engine('html', swig.renderFile);
app.set('view engine', 'html');


// *** static directory *** //
app.set('views', path.join(__dirname, 'views'));


// *** config middleware *** //
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(cookieSession({
  name: 'google-oauth-session-example',
  keys: [process.env.COOKIE_KEY1, process.env.COOKIE_KEY2]
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(express.static(path.join(__dirname, '../client')));
app.use(express.static(path.join(__dirname, '../client/image')));


// *** protect user routes *** //

app.use('/user', function (req, res, next) {
  //console.log(req.user);
  if(!req.user) {
    //console.log('denied');
    res.redirect('/login');
  } else {
    next();
  }
});

// *** google auth *** //
passport.use(new GoogleStrategy({
    clientID:     process.env.GOOGLE_CLIENT_ID,
    clientSecret: process.env.GOOGLE_CLIENT_SECRET,
{'fraction_non_alphanumeric': 0.21981981981981982, 'fraction_numerical': 0.002059202059202059, 'mean_word_length': 4.6400580551523944, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2438240', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1221, 'n_words': 245}