Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/binary-person/rammerhead/llms.txt

Use this file to discover all available pages before exploring further.

URLPath extends the built-in URL class with two convenience methods for reading query parameters. It is used throughout Rammerhead’s route handlers to extract values like id, pwd, httpProxy, and origin from incoming request URLs without the boilerplate of new URL('http://foobar' + req.url).searchParams.get(...).

Source

module.exports = class URLPath extends URL {
    constructor(path) {
        super(path, 'http://foobar');
    }
    get(param) {
        return this.searchParams.get(param);
    }
    getParams() {
        return Object.fromEntries(this.searchParams);
    }
};

Constructor

new URLPath(path)
path
string
required
A URL path string such as /newsession?pwd=secret&foo=bar. The path does not need a scheme or host — a dummy base URL (http://foobar) is used internally so that the standard URL parser can handle root-relative paths.
const URLPath = require('./src/util/URLPath');

const url = new URLPath('/editsession?id=abc123&enableShuffling=1');
Because URLPath extends URL, all standard URL properties (pathname, searchParams, href, etc.) are available in addition to the methods below.

Methods

get(param)

Returns the value of a single query parameter, or null if the parameter is absent.
get(param: string): string | null
param
string
required
The name of the query parameter to retrieve.
const url = new URLPath('/sessionexists?id=abc123');

url.get('id');  // 'abc123'
url.get('pwd'); // null

getParams()

Returns all query parameters as a plain object. Keys are parameter names; values are their string values. When a parameter appears multiple times, the last value wins (standard URLSearchParams behaviour).
getParams(): { [param: string]: string }
const url = new URLPath('/editsession?id=abc123&httpProxy=myproxy%3A8888&enableShuffling=1');

url.getParams();
// { id: 'abc123', httpProxy: 'myproxy:8888', enableShuffling: '1' }

Usage in route handlers

URLPath is used in every route handler in setupRoutes.js and RammerheadProxy.js. The following examples reflect real usage from those files. Checking the password:
const { pwd } = new URLPath(req.url).getParams();
if (config.password !== pwd) {
    // reject request
}
Reading a single parameter:
// GET /sessionexists?id=<sessionId>
const id = new URLPath(req.url).get('id');
if (!id) {
    // return bad request
}
Destructuring multiple parameters:
// GET /editsession?id=<id>&httpProxy=<host:port>&enableShuffling=<1|0>
let { id, httpProxy, enableShuffling } = new URLPath(req.url).getParams();
Extracting localStorage sync parameters:
// POST /syncLocalStorage?sessionId=<id>&origin=<origin>
const { sessionId, origin } = new URLPath(req.url).getParams();

Build docs developers (and LLMs) love