Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ 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");

app.use(cors({
origin: "*"
}));

if (process.env.NODE_ENV === "production") {
if (isProduction) {
app.use(pino({
level: "warn"
}));
Expand Down
10 changes: 3 additions & 7 deletions routes/bake.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down