diff --git a/app.js b/app.js index 71ab501..5f8bf6c 100644 --- a/app.js +++ b/app.js @@ -14,6 +14,9 @@ import bakeRouter from "./routes/bake"; import magicRouter from "./routes/magic"; import healthRouter from "./routes/health.js"; + +const isProduction = process.env.NODE_ENV === "production"; + const app = express(); app.disable("x-powered-by"); @@ -21,7 +24,7 @@ app.use(cors({ origin: "*" })); -if (process.env.NODE_ENV === "production") { +if (isProduction) { app.use(pino({ level: "warn" })); diff --git a/routes/bake.js b/routes/bake.js index 7097f7d..f05511a 100644 --- a/routes/bake.js +++ b/routes/bake.js @@ -7,14 +7,10 @@ import { bake, Dish } from "cyberchef/src/node/index.mjs"; */ router.post("/", async function bakePost(req, res, next) { try { - if (!req.body.input) { - throw new TypeError("'input' property is required in request body"); + const noRecipeOrInput = !req.body.input || !req.body.recipe; + if(noRecipeOrInput) { + throw new TypeError(`'${!req.body.input ? 'input' : 'recipe'}' property is required in request body`); } - - if (!req.body.recipe) { - throw new TypeError("'recipe' property is required in request body"); - } - const dish = await bake(req.body.input, req.body.recipe); // Attempt to translate to another type. Any translation errors