cal.pub0.org/apps/api/lib/helpers/withMiddleware.ts

38 lines
1.0 KiB
TypeScript
Raw Normal View History

import { label } from "next-api-middleware";
2022-03-30 12:17:55 +00:00
import { addRequestId } from "./addRequestid";
import { captureErrors } from "./captureErrors";
2022-06-08 16:52:25 +00:00
import { customPrismaClient } from "./customPrisma";
2022-06-06 16:17:10 +00:00
import { extendRequest } from "./extendRequest";
import {
HTTP_POST,
HTTP_DELETE,
HTTP_PATCH,
HTTP_GET,
HTTP_GET_OR_POST,
HTTP_GET_DELETE_PATCH,
} from "./httpMethods";
import { verifyApiKey } from "./verifyApiKey";
2022-07-05 18:12:14 +00:00
import { withPagination } from "./withPagination";
2022-03-30 12:17:55 +00:00
const withMiddleware = label(
{
HTTP_GET_OR_POST,
HTTP_GET_DELETE_PATCH,
2022-03-30 12:17:55 +00:00
HTTP_GET,
HTTP_PATCH,
HTTP_POST,
HTTP_DELETE,
addRequestId,
verifyApiKey,
2022-06-08 16:52:25 +00:00
customPrismaClient,
2022-06-06 16:17:10 +00:00
extendRequest,
2022-07-05 18:12:14 +00:00
pagination: withPagination,
2022-03-30 12:17:55 +00:00
sentry: captureErrors,
},
2022-06-08 16:52:25 +00:00
// The order here, determines the order of execution, put customPrismaClient before verifyApiKey always.
2022-06-18 00:16:15 +00:00
["extendRequest", "sentry", "customPrismaClient", "verifyApiKey", "addRequestId"] // <-- Provide a list of middleware to call automatically
);
2022-03-30 12:17:55 +00:00
export { withMiddleware };