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

35 lines
859 B
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-06 16:17:10 +00:00
import { customApiEndpoints } from "./customApiEndpoints";
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-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-06 16:17:10 +00:00
customApiEndpoints,
extendRequest,
2022-03-30 12:17:55 +00:00
sentry: captureErrors,
},
2022-06-06 16:17:10 +00:00
["sentry", "customApiEndpoints", "verifyApiKey", "addRequestId", "extendRequest"] // <-- Provide a list of middleware to call automatically
);
2022-03-30 12:17:55 +00:00
export { withMiddleware };