1010e2894a
* Sendgrid app and code simplification * Applying app-store-cli + impl * Fixing types * Adding features to readme * Fixing unit tests * A few last tweaks regarding UX and env vars * Applying feedback * Using calcom icons * Renaming and applying feedback * Testing user/type page fix * Standarizing Sendgrid client usage * Removing types * Reverting CloseCom changes * Stop relying on sendgrid client pkg * Fixing button and more reverting closecom changes * Revert "Stop relying on sendgrid client pkg" This reverts commitdd61851572
. * Revert "Removing types" This reverts commit1ec5ed8de2
. * Is this it? * Standardizing apis * Fixing path * Fixing throwing errors the standard way * Stop relying on getInstalledAppPath * Removing seemingly troubling code * Returning error and avoiding any outer reference * Revert "Returning error and avoiding any outer reference" This reverts commit7d32e30154
. * Revert "Removing seemingly troubling code" This reverts commiteaae772abc
. * Revert "Stop relying on getInstalledAppPath" This reverts commitbcc70fc337
. * Revert "Fixing throwing errors the standard way" This reverts commitbb1bb410fa
. * Revert "Fixing path" This reverts commita7bd83c4fb
. * Revert "Standardizing apis" This reverts commit0258a18229
. * Revert "Is this it?" This reverts commit70b3f7b98e
. * Converting APIs to legacy style * Missing reverted CloseCom test mock * Needed for the renaming * Reverting Closecom and yarn unneeded changes * Ununsed type * Testing rearranging exports * Update apps/web/components/apps/OmniInstallAppButton.tsx Co-authored-by: Omar López <zomars@me.com> * Standardizing APIs * Fixing wrong toast message on app page Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Omar López <zomars@me.com>
25 lines
800 B
TypeScript
25 lines
800 B
TypeScript
import type { NextApiHandler, NextApiRequest, NextApiResponse } from "next";
|
|
|
|
type Handlers = {
|
|
[method in "GET" | "POST" | "PATCH" | "PUT" | "DELETE"]?: Promise<{ default: NextApiHandler }>;
|
|
};
|
|
|
|
/** Allows us to split big API handlers by method */
|
|
export const defaultHandler = (handlers: Handlers) => async (req: NextApiRequest, res: NextApiResponse) => {
|
|
const handler = (await handlers[req.method as keyof typeof handlers])?.default;
|
|
// auto catch unsupported methods.
|
|
if (!handler) {
|
|
return res
|
|
.status(405)
|
|
.json({ message: `Method Not Allowed (Allow: ${Object.keys(handlers).join(",")})` });
|
|
}
|
|
|
|
try {
|
|
await handler(req, res);
|
|
return;
|
|
} catch (error) {
|
|
console.error(error);
|
|
return res.status(500).json({ message: "Something went wrong" });
|
|
}
|
|
};
|