2022-03-29 00:25:24 +00:00
|
|
|
import { label } from "next-api-middleware";
|
2022-03-30 12:17:55 +00:00
|
|
|
|
2022-03-29 00:25:24 +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";
|
2022-04-07 01:29:53 +00:00
|
|
|
import {
|
|
|
|
HTTP_POST,
|
|
|
|
HTTP_DELETE,
|
|
|
|
HTTP_PATCH,
|
|
|
|
HTTP_GET,
|
|
|
|
HTTP_GET_OR_POST,
|
|
|
|
HTTP_GET_DELETE_PATCH,
|
|
|
|
} from "./httpMethods";
|
2022-03-29 00:25:24 +00:00
|
|
|
import { verifyApiKey } from "./verifyApiKey";
|
2022-07-05 18:12:14 +00:00
|
|
|
import { withPagination } from "./withPagination";
|
2022-03-30 12:17:55 +00:00
|
|
|
|
2022-03-29 00:25:24 +00:00
|
|
|
const withMiddleware = label(
|
|
|
|
{
|
2022-04-07 01:29:53 +00:00
|
|
|
HTTP_GET_OR_POST,
|
2022-04-03 22:49:05 +00:00
|
|
|
HTTP_GET_DELETE_PATCH,
|
2022-03-30 12:17:55 +00:00
|
|
|
HTTP_GET,
|
|
|
|
HTTP_PATCH,
|
|
|
|
HTTP_POST,
|
|
|
|
HTTP_DELETE,
|
2022-03-29 00:25:24 +00:00
|
|
|
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-03-29 00:25:24 +00:00
|
|
|
},
|
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-29 00:25:24 +00:00
|
|
|
);
|
|
|
|
|
2022-03-30 12:17:55 +00:00
|
|
|
export { withMiddleware };
|