@nickhudkins/malcolm

0.1.2 • Public • Published

👴🏻 Malcolm (in the Middle)

It's Man-In-The-Middle-Proxy for Development

Usage

Create a proxy.config.ts:

export default {
  shouldProxy(origin) {
    return origin.includes("google.com");
  },
  handleRequest(req): void {
    const url = new URL(req.url);
    const logMsg = `${LOG_PREFIX} I'll Handle This (${url.host})`;
    console.log(logMsg);
  },
  async handleResponse(
    res: PassThroughResponse
  ): Promise<CallbackResponseResult | undefined> {
    if (res.headers["content-type"]?.startsWith("text/html")) {
      return {
        body: Buffer.from(`Hi from Malcolm!`),
      };
    }
    return;
  },
};

Run malcolm

Development

Working in this directory?Clone and npm run start:dev

❤️ Made with Love by @nickhudkins

Readme

Keywords

none

Package Sidebar

Install

npm i @nickhudkins/malcolm

Weekly Downloads

6

Version

0.1.2

License

ISC

Unpacked Size

8.19 kB

Total Files

10

Last publish

Collaborators

  • nickhudkins_org