Skip to content

Commit

Permalink
configure package to be used as cli tool
Browse files Browse the repository at this point in the history
  • Loading branch information
e9x committed Aug 29, 2022
1 parent c989509 commit d4ddf91
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 50 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ cache-js/*

# ignore any custom configurations
/config.js

# for any builders
*.tgz
8 changes: 8 additions & 0 deletions bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env node
'use strict';

// hack to catch any possible exceptions!
// this package isn't a cli tool, the cli being installed is just for convenience
process.chdir(__dirname);

require('./src/server.js');
72 changes: 72 additions & 0 deletions holy-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
'use strict';

const cookie = require('cookie');

module.exports = {
//// HOSTING CONFIGURATION ////

bindingAddress: '127.0.0.1',
port: process.env.PORT,
crossDomainPort: null,
publicDir: null,

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
};
},

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,

//// REWRITE HEADER CONFIGURATION ////

stripClientHeaders: [
'cf-ipcountry',
'cf-ray',
'x-forwarded-proto',
'cf-visitor',
'cf-connecting-ip',
'cdn-loop',
'x-forwarded-for'
],
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
},

//// LOGGING CONFIGURATION ////

// valid values: 'disabled', 'debug', 'traffic', 'info', 'warn', 'error'
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()
};
102 changes: 53 additions & 49 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,51 +1,55 @@
{
"name": "rammerhead",
"version": "1.2.3",
"description": "User friendly web proxy powered by testcafe-hammerhead",
"main": "src/index.js",
"scripts": {
"preinstall": "npm install --package-lock-only --ignore-scripts && npx npm-force-resolutions",
"start": "node src/server.js",
"build": "node src/build.js",
"bstart": "npm run build && npm run start",
"test": "npm run format && npm run lint && npm run build",
"lint": "eslint -c .eslintrc.json --ext .js src",
"format": "prettier --write 'src/**/*.js'",
"clientes5": "es-check es5 src/client/*.js public/**/*.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/binary-person/rammerhead.git"
},
"author": "Simon Cheng <[email protected]> (https://github.com/binary-person)",
"license": "MIT",
"bugs": {
"url": "https://github.com/binary-person/rammerhead/issues"
},
"homepage": "https://github.com/binary-person/rammerhead#readme",
"dependencies": {
"cookie": "^0.5.0",
"async-exit-hook": "^2.0.1",
"keyv-lru-files": "github:binary-person/keyv-lru-files#patch-1",
"mime": "^2.5.2",
"sticky-session-custom": "^1.2.0",
"testcafe-hammerhead": "24.5.18",
"uglify-js": "^3.15.3",
"uuid": "^8.3.2",
"ws": "^8.2.0",
"babel-eslint": "^10.1.0",
"dotenv-flow": "^3.2.0",
"eslint": "^7.32.0",
"npm-force-resolutions": "0.0.10",
"prettier": "^2.3.2"
},
"resolutions": {
"tmp": "0.2.1"
},
"files": [
"src/*",
"CHANGELOG.md",
"package.json",
"README.md"
]
"name": "rammerhead",
"version": "1.2.3",
"description": "User friendly web proxy powered by testcafe-hammerhead",
"bin": "bin.js",
"main": "src/index.js",
"scripts": {
"preinstall": "npm install --package-lock-only --ignore-scripts && npx npm-force-resolutions",
"start": "node src/server.js",
"build": "node src/build.js",
"bstart": "npm run build && npm run start",
"test": "npm run format && npm run lint && npm run build",
"lint": "eslint -c .eslintrc.json --ext .js src",
"format": "prettier --write 'src/**/*.js'",
"clientes5": "es-check es5 src/client/*.js public/**/*.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/binary-person/rammerhead.git"
},
"author": "Simon Cheng <[email protected]> (https://github.com/binary-person)",
"license": "MIT",
"bugs": {
"url": "https://github.com/binary-person/rammerhead/issues"
},
"homepage": "https://github.com/binary-person/rammerhead#readme",
"dependencies": {
"cookie": "^0.5.0",
"async-exit-hook": "^2.0.1",
"keyv-lru-files": "github:binary-person/keyv-lru-files#patch-1",
"mime": "^2.5.2",
"sticky-session-custom": "^1.2.0",
"testcafe-hammerhead": "24.5.18",
"uglify-js": "^3.15.3",
"uuid": "^8.3.2",
"ws": "^8.2.0",
"babel-eslint": "^10.1.0",
"dotenv-flow": "^3.2.0",
"eslint": "^7.32.0",
"npm-force-resolutions": "0.0.10",
"prettier": "^2.3.2"
},
"resolutions": {
"tmp": "0.2.1"
},
"files": [
"src/*",
"holy-config.js",
"CHANGELOG.md",
"package.json",
"README.md",
"sessions/.gitkeep",
"cache-js/.gitkeep"
]
}
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ module.exports = {
// getIP: 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'));
if (fs.existsSync(path.join(__dirname, '../holy-config.js'))) Object.assign(module.exports, require('../holy-config'));

0 comments on commit d4ddf91

Please sign in to comment.