Skip to content

Commit

Permalink
Changed ReceiverRoutes to a Map of ReceiverRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
satcheluniverse committed Mar 28, 2023
1 parent 00eed6f commit 04ba9e0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/receivers/HTTPReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
HTTPReceiverDeferredRequestError,
CodedError,
} from '../errors';
import { CustomRoute, buildReceiverRoutes, ReceiverRoutes } from './custom-routes';
import { CustomRoute, buildReceiverRoutes, ReceiverRoutes, ReceiverRoute } from './custom-routes';
import { StringIndexed } from '../types/helpers';
import { BufferedIncomingMessage } from './BufferedIncomingMessage';
import {
Expand Down Expand Up @@ -120,7 +120,7 @@ export default class HTTPReceiver implements Receiver {

private port: number; // you can override this value by the #start() method argument

private routes: ReceiverRoutes;
private routes: ReceiverRoutes<ReceiverRoute>;

private signingSecret: string;

Expand Down
4 changes: 2 additions & 2 deletions src/receivers/SocketModeReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import App from '../App';
import { CodedError } from '../errors';
import { Receiver, ReceiverEvent } from '../types';
import { StringIndexed } from '../types/helpers';
import { buildReceiverRoutes, ReceiverRoutes } from './custom-routes';
import { buildReceiverRoutes, ReceiverRoutes, ReceiverRoute } from './custom-routes';
import { verifyRedirectOpts } from './verify-redirect-opts';
import {
SocketModeFunctions as socketModeFunc,
Expand Down Expand Up @@ -81,7 +81,7 @@ export default class SocketModeReceiver implements Receiver {

private httpServerPort?: number;

private routes: ReceiverRoutes;
private routes: ReceiverRoutes<ReceiverRoute>;

private processEventErrorHandler: (args: SocketModeReceiverProcessEventErrorHandlerArgs) => Promise<boolean>;

Expand Down
14 changes: 8 additions & 6 deletions src/receivers/custom-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ export interface CustomRoute {
handler: (req: ParamsIncomingMessage, res: ServerResponse) => void;
}

export interface ReceiverRoutes {
[url: string]: {
[method: string]: (req: ParamsIncomingMessage, res: ServerResponse) => void;
};
export interface ReceiverRoute {
[method: string]: (req: ParamsIncomingMessage, res: ServerResponse) => void;
}

export function buildReceiverRoutes(customRoutes: CustomRoute[]): ReceiverRoutes {
const routes: ReceiverRoutes = {};
export interface ReceiverRoutes<T> {
[url: string]: T;
}

export function buildReceiverRoutes(customRoutes: CustomRoute[]): ReceiverRoutes<ReceiverRoute> {
const routes: ReceiverRoutes<ReceiverRoute> = {};

validateCustomRoutes(customRoutes);

Expand Down

0 comments on commit 04ba9e0

Please sign in to comment.