1.120.0 • Published 8 months ago

@biorate/proxy v1.120.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Proxy

Proxy connector

Features:

  • connection manager for simple proxy with/without http liveness probe
  • patroni compatible
  • stats page

Examples:

import { Server as HTTPServer } from 'http';
import { Server as TCPServer } from 'net';
import { inject, container, Types, Core } from '@biorate/inversion';
import { IConfig, Config } from '@biorate/config';
import { ProxyConnector } from '@biorate/proxy';

const httpPort = 8001;
const clientPort = 7001;
const serverPort = 7002;

export class Root extends Core() {
  public static connect() {
    const socket = new TCPSocket();
    socket.connect(serverPort);
    return socket;
  }

  @inject(ProxyConnector) public connector: ProxyConnector;

  public http: HTTPServer;

  public tcp: TCPServer;

  protected constructor() {
    super();
    this.http = new HTTPServer();
    this.http.listen(httpPort);
    this.http.on('request', (req, res) => {
      res.writeHead(200);
      res.end('1');
    });
    this.tcp = new TCPServer();
    this.tcp.listen(clientPort);
    this.tcp.on('connection', (socket) =>
      socket.on('data', (data) => socket.write(`${data} world!`)),
    );
  }
}

container.bind<IConfig>(Types.Config).to(Config).inSingletonScope();
container.bind<ProxyConnector>(ProxyConnector).toSelf().inSingletonScope();
container.bind<Root>(Root).toSelf().inSingletonScope();

container.get<IConfig>(Types.Config).merge({
  Proxy: [
    {
      name: 'connection',
      retry: 10,
      server: {
        address: {
          host: 'localhost',
          port: serverPort,
        },
      },
      clients: [
        {
          liveness: `http://localhost:${httpPort}`,
          address: {
            host: 'localhost',
            port: clientPort,
          },
        },
      ],
    },
  ],
});

(async () => {
  const root = <Root>container.get<Root>(Root);
  await root.$run();
  const socket = Root.connect();
  socket.write('Hello');
  socket.on('data', (data) => {
    console.log(data.toString()); // Hello world!
  });
})();

Learn

  • Documentation can be found here - docs.

Release History

See the CHANGELOG

License

MIT

Copyright (c) 2021-present Leonid Levkin (llevkin)

1.96.2

11 months ago

1.96.1

11 months ago

1.96.0

12 months ago

1.95.1

12 months ago

1.91.5

1 year ago

1.95.0

12 months ago

1.91.4

1 year ago

1.93.1

12 months ago

1.91.3

1 year ago

1.93.0

12 months ago

1.91.2

1 year ago

1.91.1

1 year ago

1.91.0

1 year ago

1.90.0

1 year ago

1.100.0

10 months ago

1.120.0

8 months ago

1.104.0

10 months ago

1.102.0

10 months ago

1.102.1

10 months ago

1.112.0

8 months ago

1.110.0

9 months ago

1.117.0

8 months ago

1.115.0

8 months ago

1.116.0

8 months ago

1.114.0

8 months ago

1.87.2

1 year ago

1.84.1

1 year ago

1.86.0

1 year ago

1.76.3

1 year ago

1.65.9

2 years ago

1.65.8

2 years ago

1.65.4

2 years ago

1.65.3

2 years ago

1.65.2

2 years ago

1.65.1

2 years ago

1.65.0

2 years ago

1.64.0

2 years ago