forked from binary-person/rammerhead
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
140 lines (114 loc) · 5.13 KB
/
Copy pathconfig.js
File metadata and controls
140 lines (114 loc) · 5.13 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const path = require('path');
const cookie = require('cookie');
const fs = require('fs');
const os = require('os');
const RammerheadJSMemCache = require('./classes/RammerheadJSMemCache.js');
const RammerheadJSFileCache = require('./classes/RammerheadJSFileCache.js');
const enableWorkers = os.cpus().length !== 1;
module.exports = {
//// HOSTING CONFIGURATION ////
bindingAddress: '0.0.0.0',
port: 8080,
crossDomainPort: 8081,
publicDir: null, // set to null to disable
// enable or disable multithreading
enableWorkers,
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) {
origin = new URL(`${req.socket.encrypted ? 'https:' : 'http:'}//${req.headers.host}`);
}
const { hostname, port, protocol } = origin;
return {
hostname,
port,
crossDomainPort: port,
protocol
};
},
//modified from rammerhead-heroku
getServerInfoProxy: (req) => {
let origin;
try {
origin = new URL(req.headers.origin);
} catch (error) {
origin = new URL(`https://${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,
// caching options for js rewrites. (disk caching not recommended for slow HDD disks)
// recommended: 50mb for memory, 5gb for disk
// jsCache: new RammerheadJSMemCache(5 * 1024 * 1024),
jsCache: new RammerheadJSFileCache(
path.join(__dirname, '../cache-js'),
5 * 1024 * 1024 * 1024,
50000,
enableWorkers
),
// whether to disable http2 support or not (from proxy to destination site).
// disabling may reduce number of errors/memory, but also risk
// removing support for picky sites like web.whatsapp.com that want
// the client to connect to http2 before connecting to their websocket
disableHttp2: false,
//// 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: {},
//// 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.socket.remoteAddress,
getIPProxy: req => (req.headers['x-forwarded-for'] || req.connection.remoteAddress || '').split(',')[0].trim()
};
if (fs.existsSync(path.join(__dirname, '../config.js'))) Object.assign(module.exports, require('../config'));