Skip to content

Commit 505f739

Browse files
bitgopatmclericcrosson-bitgo
authored andcommitted
fix(io-ts-express): support async route handlers
This is the intended behavior Ticket: BG-45914
1 parent f298a5c commit 505f739

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

packages/io-ts-express/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import {
1414
ResponseType,
1515
} from '@bitgo/io-ts-http';
1616

17-
export type Function<R extends HttpRoute> = (input: RequestType<R>) => ResponseType<R>;
17+
export type Function<R extends HttpRoute> = (
18+
input: RequestType<R>,
19+
) => ResponseType<R> | Promise<ResponseType<R>>;
1820
export type RouteStack<R extends HttpRoute> = [
1921
...express.RequestHandler[],
2022
Function<R>,

packages/io-ts-express/test/test-server.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@ import * as t from 'io-ts';
44
import express from 'express';
55
import supertest from 'supertest';
66

7-
import {
8-
ApiSpec,
9-
apiSpec,
10-
httpRequest,
11-
httpRoute,
12-
optional,
13-
RequestType,
14-
ResponseType,
15-
} from '@bitgo/io-ts-http';
7+
import { ApiSpec, apiSpec, httpRequest, httpRoute, optional } from '@bitgo/io-ts-http';
168
import { Response } from '@bitgo/io-ts-response';
179
import {
1810
buildApiClient,
@@ -70,9 +62,7 @@ const routeMiddleware: express.RequestHandler = (req, _res, next) => {
7062
};
7163

7264
// DISCUSS: defining a RouteHandler type or something (also used in decodeRequestAndEncodeResponse)
73-
const CreateHelloWorld: (
74-
parameters: RequestType<PutHello>,
75-
) => ResponseType<PutHello> = (parameters: {
65+
const CreateHelloWorld = async (parameters: {
7666
secretCode: number;
7767
appMiddlewareRan?: boolean;
7868
routeMiddlewareRan?: boolean;

0 commit comments

Comments
 (0)