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

45 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,
2023-08-03 15:22:38 +00:00
captureErrors,
},
2023-08-03 15:22:38 +00:00
// The order here, determines the order of execution
[
"extendRequest",
"captureErrors",
// - Put customPrismaClient before verifyApiKey always.
"customPrismaClient",
"verifyApiKey",
"addRequestId",
] // <-- Provide a list of middleware to call automatically
);
2022-03-30 12:17:55 +00:00
export { withMiddleware };