Skip to content

Repository files navigation

lonesome-js

High-performance programmable reverse proxy bindings for Node.js, built on top of Pingora.

中文文档 (README.zh.md)

Why lonesome-js

  • Built on Pingora for modern async proxy performance and reliability.
  • Runtime route updates (addOrUpdate) with Node.js without process restarts.
  • Request matching and middleware conditions powered by CEL expressions.
  • virtual_js upstream mode for in-process Node.js service composition.
  • Route middlewares for auth, headers, redirects, caching, compression, CORS, rate limiting, and programmable interception.

How It Differs From Traditional Reverse Proxies

Most reverse proxies focus on static config files and process-level reload workflows. lonesome-js is designed around a runtime API and programmable request flow.

CEL-Driven Routing and Middleware Logic

Instead of limiting logic to fixed directives, routes and middleware conditions can use CEL expressions for matching and value generation.

Examples:

  • Route match: "Method('POST') && PathPrefix('/api') && Query('debug', '1')"
  • Conditional middleware: rule: "Header('x-env', 'prod')"
  • Dynamic value: expression: "MethodValue() + '-' + QueryValue('id')"

virtual_js Upstreams

Beyond TCP/Unix socket upstreams, virtual_js allows requests to be bridged into JavaScript handlers in-process. This makes it possible to build internal adapters and programmable backends without opening extra network ports.

Quick Start

1. Install

npm i lonesome-js

Windows on arm prebuilt binding is not available; use WSL as a temporary workaround, or build it yourself.

2. Start a proxy server

import { LonesomeServer } from 'lonesome-js'

const server = new LonesomeServer()

server.start({
  listeners: [{ kind: 'tcp', addr: '127.0.0.1:8080' }],
})

3. Add a basic route

server.addOrUpdate({
  id: 'basic-proxy',
  matcher: { rule: "PathPrefix('/api')", priority: 50 },
  middlewares: [],
  upstreams: [
    { kind: 'tcp', address: '127.0.0.1:9000' },
  ],
  loadBalancer: { algorithm: 'round_robin' },
})

4. Hot-update the route at runtime

server.addOrUpdate({
  id: 'basic-proxy',
  matcher: { rule: "PathPrefix('/api')", priority: 50 },
  middlewares: [{ type: 'respond', config: { status: 418, body: 'teapot' } }],
  upstreams: [
    { kind: 'tcp', address: '127.0.0.1:9000' },
  ],
})

Runtime Compatibility

  • Primary target: Node.js via the npm package.
  • Deno can consume the package through npm:lonesome-js for local/server use cases that allow npm/native bindings. See the example app: example/lonesome-lake.

Documentation

About

High-performance programmable reverse proxy bindings for Node.js, built on top of Pingora.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages