Path: blob/master/lib/rammerhead/src/config.js
5256 views
const cookie = require('cookie');1const path = require('path');2const fs = require('fs');3const os = require('os');45module.exports = {6//// HOSTING CONFIGURATION ////78bindingAddress: '127.0.0.1',9port: process.env.PORT,10crossDomainPort: null,11publicDir: path.join(__dirname, '../public'), // set to null to disable1213// if workers is null or 1, multithreading is disabled14workers: os.cpus().length,1516// ssl object is either null or { key: fs.readFileSync('path/to/key'), cert: fs.readFileSync('path/to/cert') }17// for more info, see https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener18ssl: null,1920// this function's return object will determine how the client url rewriting will work.21// set them differently from bindingAddress and port if rammerhead is being served22// from a reverse proxy.23getServerInfo: (req) => {24const { origin_proxy } = cookie.parse(req.headers.cookie || '');2526let origin;2728try {29origin = new URL(origin_proxy);30} catch (error) {31console.log(error, req.headers.cookie);32origin = new URL(`${req.socket.encrypted ? 'https:' : 'http:'}//${req.headers.host}`);33}3435const { hostname, port, protocol } = origin;3637return {38hostname,39port,40crossDomainPort: port,41protocol42};43},44// example of non-hard-coding the hostname header45// getServerInfo: (req) => {46// return { hostname: new URL('http://' + req.headers.host).hostname, port: 443, crossDomainPort: 8443, protocol: 'https: };47// },4849// enforce a password for creating new sessions. set to null to disable50password: null,5152// disable or enable localStorage sync (turn off if clients send over huge localStorage data, resulting in huge memory usages)53disableLocalStorageSync: false,5455// restrict sessions to be only used per IP56restrictSessionToIP: true,5758// use disk for caching js rewrites. set to null to use memory instead (not recommended for HDD disks)59diskJsCachePath: path.join(__dirname, '../cache-js'),60jsCacheSize: 5 * 1024 * 1024 * 1024, // recommended: 50mb for memory, 5gb for disk6162//// REWRITE HEADER CONFIGURATION ////6364// removes reverse proxy headers65// cloudflare example:66// stripClientHeaders: ['cf-ipcountry', 'cf-ray', 'x-forwarded-proto', 'cf-visitor', 'cf-connecting-ip', 'cdn-loop', 'x-forwarded-for'],67stripClientHeaders: [],68// if you want to modify response headers, like removing the x-frame-options header, do it like so:69// rewriteServerHeaders: {70// // you can also specify a function to modify/add the header using the original value (undefined if adding the header)71// // 'x-frame-options': (originalHeaderValue) => '',72// 'x-frame-options': null, // set to null to tell rammerhead that you want to delete it73// },74rewriteServerHeaders: {75// you can also specify a function to modify/add the header using the original value (undefined if adding the header)76// 'x-frame-options': (originalHeaderValue) => '',77'x-frame-options': null // set to null to tell rammerhead that you want to delete it78},7980//// SESSION STORE CONFIG ////8182// see src/classes/RammerheadSessionFileCache.js for more details and options83fileCacheSessionConfig: {84saveDirectory: path.join(__dirname, '../sessions'),85cacheTimeout: 1000 * 60 * 20, // 20 minutes86cacheCheckInterval: 1000 * 60 * 10, // 10 minutes87deleteUnused: true,88staleCleanupOptions: {89staleTimeout: 1000 * 60 * 60 * 24 * 3, // 3 days90maxToLive: null,91staleCheckInterval: 1000 * 60 * 60 * 6 // 6 hours92},93// corrupted session files happens when nodejs exits abruptly while serializing the JSON sessions to disk94deleteCorruptedSessions: true,95},9697//// LOGGING CONFIGURATION ////9899// valid values: 'disabled', 'debug', 'traffic', 'info', 'warn', 'error'100logLevel: process.env.DEVELOPMENT ? 'debug' : 'info',101generatePrefix: (level) => `[${new Date().toISOString()}] [${level.toUpperCase()}] `,102103// logger depends on this value104getIP: (req) => (req.headers['x-forwarded-for'] || req.connection.remoteAddress || '').split(',')[0].trim()105// use the example below if rammerhead is sitting behind a reverse proxy like nginx106// getIP: req => (req.headers['x-forwarded-for'] || req.connection.remoteAddress || '').split(',')[0].trim()107};108109if (fs.existsSync(path.join(__dirname, '../holy-config.js'))) Object.assign(module.exports, require('../holy-config'));110111112