<commit_before>const fs = require('fs')
const path = require('path')
const crypto = require('crypto')
const express = require('express')
const helmet = require('helmet')
const session = require('express-session')
const MemoryStore = require('memorystore')(session)
const config = require('./lib/config.js')
const packageJson = require('./package.json')

/*  Env/Cli Config stuff
============================================================================= */
const BASE_URL = config.get('baseUrl')
const GOOGLE_CLIENT_ID = config.get('googleClientId')
const GOOGLE_CLIENT_SECRET = config.get('googleClientSecret')
const PUBLIC_URL = config.get('publicUrl')
const DEBUG = config.get('debug')

/*  Express setup
============================================================================= */
const bodyParser = require('body-parser')
const favicon = require('serve-favicon')
const morgan = require('morgan')
const passport = require('passport')
const errorhandler = require('errorhandler')

const app = express()

// Use default helmet protections and add referrerPolicy
app.use(helmet())
app.use(helmet.referrerPolicy({ policy: 'same-origin' }))

app.locals.title = 'SQLPad'
app.locals.version = packageJson.version
app.set('env', DEBUG ? 'development' : 'production')

if (DEBUG) {
  app.use(errorhandler())
}
app.use(favicon(path.join(__dirname, '/public/images/favicon.ico')))
app.use(bodyParser.json())
app.use(
  bodyParser.urlencoded({
    extended: true
  })
)

// Cookie secrets are generated randomly at server start
// SQLPad (currently) is designed for running as a single instance
// so this should be okay unless SQLPad is frequently restarting
const cookieSecrets = [1, 2, 3, 4].map(n =>
  crypto.randomBytes(64).toString('hex')
)
const ONE_HOUR = 1000 * 60 * 60
app.use(
  session({
    store: new MemoryStore({
      checkPeriod: ONE_HOUR
    }),
    saveUninitialized: false,
    resave: false,
    cookie: { maxAge: ONE_HOUR },
    secret: cookieSecrets
  })
)

app.use(passport.initialize())
app.use(passport.session())
app.use(BASE_URL, express.static(path.join(__dirname, 'build')))
if (DEBUG) {
  app.use(morgan('dev'))
}<commit_msg>force a session identifier cookie to be set on every response<commit_after>const fs = require('fs')
const path = require('path')
const crypto = require('crypto')
const express = require('express')
const helmet = require('helmet')
const session = require('express-session')
const MemoryStore = require('memorystore')(session)
const config = require('./lib/config.js')
const packageJson = require('./package.json')

/*  Env/Cli Config stuff
============================================================================= */
const BASE_URL = config.get('baseUrl')
const GOOGLE_CLIENT_ID = config.get('googleClientId')
const GOOGLE_CLIENT_SECRET = config.get('googleClientSecret')
const PUBLIC_URL = config.get('publicUrl')
const DEBUG = config.get('debug')

/*  Express setup
============================================================================= */
const bodyParser = require('body-parser')
const favicon = require('serve-favicon')
const morgan = require('morgan')
const passport = require('passport')
const errorhandler = require('errorhandler')

const app = express()

// Use default helmet protections and add referrerPolicy
app.use(helmet())
app.use(helmet.referrerPolicy({ policy: 'same-origin' }))

app.locals.title = 'SQLPad'
app.locals.version = packageJson.version
app.set('env', DEBUG ? 'development' : 'production')

if (DEBUG) {
  app.use(errorhandler())
}
app.use(favicon(path.join(__dirname, '/public/images/favicon.ico')))
app.use(bodyParser.json())
app.use(
  bodyParser.urlencoded({
    extended: true
  })
)

// Cookie secrets are generated randomly at server start
// SQLPad (currently) is designed for running as a single instance
// so this should be okay unless SQLPad is frequently restarting
const cookieSecrets = [1, 2, 3, 4].map(n =>
  crypto.randomBytes(64).toString('hex')
)
const ONE_HOUR = 1000 * 60 * 60
app.use(
  session({
    store: new MemoryStore({
      checkPeriod: ONE_HOUR
    }),
    saveUninitialized: false,
    resave: false,
    rolling: true,
    cookie: { maxAge: ONE_HOUR },
    secret: cookieSecrets
  })
)

app.use(passport.initialize())
app.use(passport.session())
app.use(BASE_URL, express.static(path.join(__dirname, 'build')))
if (DEBUG) {
  app.use(morgan('dev'))
}
{'fraction_non_alphanumeric': 0.20598310116464946, 'fraction_numerical': 0.0063941539164192734, 'mean_word_length': 5.508172362555721, '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': '5113143', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1269, 'n_words': 328}