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