Skip to content

Commit

Permalink
feat: add support for custom resolvers certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
manast committed Sep 19, 2024
1 parent 4c139b7 commit 7dcc0c9
Show file tree
Hide file tree
Showing 15 changed files with 468 additions and 350 deletions.
2 changes: 1 addition & 1 deletion lib/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class DockerModule {
const Dolphin = require('dolphin');

this.redbird = redbird;
this.log = redbird.log;
this.log = redbird.logger;

const targets: Record<string, Record<string, string>> = (this.targets = {});
this.ports = {};
Expand Down
2 changes: 1 addition & 1 deletion lib/etcd-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class ETCDModule {

// Create Redbird Instance and Log
this.redbird = redbird;
const log = redbird.log;
const log = redbird.logger;
const _this = this;

// Create node-etcd Instance
Expand Down
16 changes: 2 additions & 14 deletions lib/interfaces/proxy-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,7 @@ import http, { IncomingMessage, ServerResponse } from 'http';
import httpProxy, { ProxyTargetUrl } from 'http-proxy';
import { Socket } from 'net';
import pino from 'pino';

type ResolverFnResult = string | { path: string; url: string } | null | undefined;

export type ResolverFn = (
host: string,
url: string,
req?: IncomingMessage
) => ResolverFnResult | Promise<ResolverFnResult>;

export interface Resolver {
fn: ResolverFn;
priority: number;
}
import { Resolver } from './resolver.js';

export interface SSLConfig {
port?: number;
Expand All @@ -39,7 +27,7 @@ export interface ProxyOptions {
httpProxy?: httpProxy.ServerOptions;

// Enable Logging
log?: pino.LoggerOptions;
logger?: pino.Logger;

// Enable Cluster Mode
cluster?: number;
Expand Down
16 changes: 4 additions & 12 deletions lib/interfaces/proxy-route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { ProxyTargetUrl } from './proxy-target-url.js';
import { RouteOptions } from './route-options.js';

/**
* ProxyRoute interface
* @description
Expand All @@ -8,16 +11,5 @@ export interface ProxyRoute {
path?: string;
rr?: number;
isResolved?: boolean;
opts?: {
onRequest?: (req: any, res: any, target: ProxyTargetUrl) => void;
};
}

export interface ProxyTargetUrl {
host: string;
hostname: string;
port: number;
pathname: string;
useTargetHostHeader: boolean;
href: string;
opts?: RouteOptions;
}
8 changes: 8 additions & 0 deletions lib/interfaces/proxy-target-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface ProxyTargetUrl {
host: string;
hostname: string;
port: number;
pathname: string;
useTargetHostHeader: boolean;
href: string;
}
19 changes: 19 additions & 0 deletions lib/interfaces/resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { IncomingMessage } from 'http';
import { RouteOptions } from './route-options.js';

export type ResolverFnResult =
| string
| { path?: string; url: string; opts?: RouteOptions }
| null
| undefined;

export type ResolverFn = (
host: string,
url: string,
req?: IncomingMessage
) => ResolverFnResult | Promise<ResolverFnResult>;

export interface Resolver {
fn: ResolverFn;
priority: number;
}
12 changes: 12 additions & 0 deletions lib/interfaces/route-options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ProxyTargetUrl } from './proxy-target-url.js';

export interface RouteOptions {
useTargetHostHeader?: boolean;
ssl?: {
key?: string;
cert?: string;
ca?: string;
letsencrypt?: { email: string; production: boolean; lazy?: boolean };
};
onRequest?: (req: any, res: any, target: ProxyTargetUrl) => void;
}
Loading

0 comments on commit 7dcc0c9

Please sign in to comment.