forked from trpc/trpc-openapi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
handler.ts
27 lines (23 loc) · 786 Bytes
/
handler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { awsLambdaRequestHandler } from '@trpc/server/adapters/aws-lambda';
import { createOpenApiAwsLambdaHandler } from 'trpc-openapi';
import { openApiDocument } from './src/openapi';
import { appRouter, createContext } from './src/router';
// Handle incoming tRPC requests
export const trpcHandler = awsLambdaRequestHandler({
router: appRouter,
createContext,
});
// Handle incoming OpenAPI requests
export const trpcOpenApiHandler = createOpenApiAwsLambdaHandler({
router: appRouter,
createContext,
});
// Serve our OpenAPI schema
// eslint-disable-next-line @typescript-eslint/require-await
export const openApiJson = async () => {
return {
statusCode: 200,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(openApiDocument),
};
};