Skip to content

Commit 0ffee2e

Browse files
committed
Send http 404 when algorithm not found
1 parent f025e88 commit 0ffee2e

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

app/frontend.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,22 @@ app.use((req, res) => {
5656

5757
const [, categoryKey, algorithmKey] = url.parse(req.originalUrl).pathname.split('/');
5858
let { title, description } = packageJson;
59-
const algorithm = hierarchy.find(categoryKey, algorithmKey);
60-
if (algorithm) {
61-
title = [algorithm.categoryName, algorithm.algorithmName].join(' - ');
62-
description = algorithm.description;
59+
let algorithm = undefined;
60+
if (categoryKey && categoryKey !== 'scratch-paper') {
61+
algorithm = hierarchy.find(categoryKey, algorithmKey) || null;
62+
if (algorithm) {
63+
title = [algorithm.categoryName, algorithm.algorithmName].join(' - ');
64+
description = algorithm.description;
65+
} else {
66+
res.status(404);
67+
}
6368
}
6469

6570
const indexFile = res.indexFile
6671
.replace(/\$TITLE/g, title)
6772
.replace(/\$DESCRIPTION/g, description)
68-
.replace(/\$ALGORITHM/g, algorithm ? JSON.stringify(algorithm).replace(/</g, '\\u003c') : 'undefined');
73+
.replace(/\$ALGORITHM/g, algorithm === undefined ? 'undefined' :
74+
JSON.stringify(algorithm).replace(/</g, '\\u003c'));
6975
res.send(indexFile);
7076
});
7177

src/frontend/components/App/index.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ class App extends BaseComponent {
148148
if (window.__PRELOADED_ALGORITHM__) {
149149
this.props.setAlgorithm(window.__PRELOADED_ALGORITHM__);
150150
delete window.__PRELOADED_ALGORITHM__;
151+
} else if (window.__PRELOADED_ALGORITHM__ === null) {
152+
delete window.__PRELOADED_ALGORITHM__;
153+
return Promise.reject(new Error('Algorithm Not Found'));
151154
} else if (categoryKey && algorithmKey) {
152155
return AlgorithmApi.getAlgorithm(categoryKey, algorithmKey)
153156
.then(({ algorithm }) => this.props.setAlgorithm(algorithm));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy