This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
forked from binary-person/rammerhead
-
Notifications
You must be signed in to change notification settings - Fork 24
/
config.js
110 lines (89 loc) · 4.61 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const cookie = require('cookie');
const path = require('path');
const fs = require('fs');
const os = require('os');
module.exports = {
//// HOSTING CONFIGURATION ////
bindingAddress: '127.0.0.1',
port: process.env.PORT,
crossDomainPort: null,
publicDir: path.join(__dirname, '../public'), // set to null to disable
// if workers is null or 1, multithreading is disabled
workers: os.cpus().length,
// ssl object is either null or { key: fs.readFileSync('path/to/key'), cert: fs.readFileSync('path/to/cert') }
// for more info, see https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener
ssl: null,
// this function's return object will determine how the client url rewriting will work.
// set them differently from bindingAddress and port if rammerhead is being served
// from a reverse proxy.
getServerInfo: (req) => {
const { origin_proxy } = cookie.parse(req.headers.cookie || '');
let origin;
try {
origin = new URL(origin_proxy);
} catch (error) {
console.log(error, req.headers.cookie);
origin = new URL(`${req.socket.encrypted ? 'https:' : 'http:'}//${req.headers.host}`);
}
const { hostname, port, protocol } = origin;
return {
hostname,
port,
crossDomainPort: port,
protocol
};
},
// example of non-hard-coding the hostname header
// getServerInfo: (req) => {
// return { hostname: new URL('http://' + req.headers.host).hostname, port: 443, crossDomainPort: 8443, protocol: 'https: };
// },
// enforce a password for creating new sessions. set to null to disable
password: null,
// disable or enable localStorage sync (turn off if clients send over huge localStorage data, resulting in huge memory usages)
disableLocalStorageSync: false,
// restrict sessions to be only used per IP
restrictSessionToIP: true,
// use disk for caching js rewrites. set to null to use memory instead (not recommended for HDD disks)
diskJsCachePath: path.join(__dirname, '../cache-js'),
jsCacheSize: 5 * 1024 * 1024 * 1024, // recommended: 50mb for memory, 5gb for disk
//// REWRITE HEADER CONFIGURATION ////
// removes reverse proxy headers
// cloudflare example:
// stripClientHeaders: ['cf-ipcountry', 'cf-ray', 'x-forwarded-proto', 'cf-visitor', 'cf-connecting-ip', 'cdn-loop', 'x-forwarded-for'],
stripClientHeaders: [],
// if you want to modify response headers, like removing the x-frame-options header, do it like so:
// rewriteServerHeaders: {
// // you can also specify a function to modify/add the header using the original value (undefined if adding the header)
// // 'x-frame-options': (originalHeaderValue) => '',
// 'x-frame-options': null, // set to null to tell rammerhead that you want to delete it
// },
rewriteServerHeaders: {
// you can also specify a function to modify/add the header using the original value (undefined if adding the header)
// 'x-frame-options': (originalHeaderValue) => '',
'x-frame-options': null // set to null to tell rammerhead that you want to delete it
},
//// SESSION STORE CONFIG ////
// see src/classes/RammerheadSessionFileCache.js for more details and options
fileCacheSessionConfig: {
saveDirectory: path.join(__dirname, '../sessions'),
cacheTimeout: 1000 * 60 * 20, // 20 minutes
cacheCheckInterval: 1000 * 60 * 10, // 10 minutes
deleteUnused: true,
staleCleanupOptions: {
staleTimeout: 1000 * 60 * 60 * 24 * 3, // 3 days
maxToLive: null,
staleCheckInterval: 1000 * 60 * 60 * 6 // 6 hours
},
// corrupted session files happens when nodejs exits abruptly while serializing the JSON sessions to disk
deleteCorruptedSessions: true,
},
//// LOGGING CONFIGURATION ////
// valid values: 'disabled', 'debug', 'traffic', 'info', 'warn', 'error'
logLevel: process.env.DEVELOPMENT ? 'debug' : 'info',
generatePrefix: (level) => `[${new Date().toISOString()}] [${level.toUpperCase()}] `,
// logger depends on this value
getIP: (req) => (req.headers['x-forwarded-for'] || req.connection.remoteAddress || '').split(',')[0].trim()
// use the example below if rammerhead is sitting behind a reverse proxy like nginx
// getIP: req => (req.headers['x-forwarded-for'] || req.connection.remoteAddress || '').split(',')[0].trim()
};
if (fs.existsSync(path.join(__dirname, '../holy-config.js'))) Object.assign(module.exports, require('../holy-config'));