From 0ffee2e5dc76abedd043c273f597a9a9e2bc732a Mon Sep 17 00:00:00 2001 From: Jason Park Date: Thu, 24 Jan 2019 02:59:56 -0500 Subject: [PATCH] Send http 404 when algorithm not found --- app/frontend.js | 16 +++++++++++----- src/frontend/components/App/index.jsx | 3 +++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/frontend.js b/app/frontend.js index 4c50071..d54c3fb 100644 --- a/app/frontend.js +++ b/app/frontend.js @@ -56,16 +56,22 @@ app.use((req, res) => { const [, categoryKey, algorithmKey] = url.parse(req.originalUrl).pathname.split('/'); let { title, description } = packageJson; - const algorithm = hierarchy.find(categoryKey, algorithmKey); - if (algorithm) { - title = [algorithm.categoryName, algorithm.algorithmName].join(' - '); - description = algorithm.description; + let algorithm = undefined; + if (categoryKey && categoryKey !== 'scratch-paper') { + algorithm = hierarchy.find(categoryKey, algorithmKey) || null; + if (algorithm) { + title = [algorithm.categoryName, algorithm.algorithmName].join(' - '); + description = algorithm.description; + } else { + res.status(404); + } } const indexFile = res.indexFile .replace(/\$TITLE/g, title) .replace(/\$DESCRIPTION/g, description) - .replace(/\$ALGORITHM/g, algorithm ? JSON.stringify(algorithm).replace(/ this.props.setAlgorithm(algorithm));