Skip to content

Commit

Permalink
Add config validation endpoint: /config/validate
Browse files Browse the repository at this point in the history
  • Loading branch information
RedwanPlague committed Sep 25, 2023
1 parent 526dd30 commit 8d5e490
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pages/api/config/validate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { NextApiRequest, NextApiResponse } from "next";

const handler = async (req: NextApiRequest, res: Response) => {
if (req.method !== "POST") {
res.status(405).send({ message: "Only POST method allowed" });
return;
}

const shade = req.body.shade;
const validShades = ["red", "green", "blue"];
if (shade == null || validShades.includes(shade)) {
res.status(200).json({ message: "OK" });
return;
}

res.status(422).json({
message: `Shade cannot be ${shade}`,
details: {
shade: {
message: `Shade cannot be ${shade}`,
},
},
});
};

type Response = NextApiResponse<{
message: string;
details?: {
[key: string]: { message: string };
};
}>;

export default handler;

0 comments on commit 8d5e490

Please sign in to comment.