File tree 2 files changed +14
-5
lines changed
src/frontend/components/App
2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -56,16 +56,22 @@ app.use((req, res) => {
56
56
57
57
const [ , categoryKey , algorithmKey ] = url . parse ( req . originalUrl ) . pathname . split ( '/' ) ;
58
58
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
+ }
63
68
}
64
69
65
70
const indexFile = res . indexFile
66
71
. replace ( / \$ T I T L E / g, title )
67
72
. replace ( / \$ D E S C R I P T I O N / g, description )
68
- . replace ( / \$ A L G O R I T H M / g, algorithm ? JSON . stringify ( algorithm ) . replace ( / < / g, '\\u003c' ) : 'undefined' ) ;
73
+ . replace ( / \$ A L G O R I T H M / g, algorithm === undefined ? 'undefined' :
74
+ JSON . stringify ( algorithm ) . replace ( / < / g, '\\u003c' ) ) ;
69
75
res . send ( indexFile ) ;
70
76
} ) ;
71
77
Original file line number Diff line number Diff line change @@ -148,6 +148,9 @@ class App extends BaseComponent {
148
148
if ( window . __PRELOADED_ALGORITHM__ ) {
149
149
this . props . setAlgorithm ( window . __PRELOADED_ALGORITHM__ ) ;
150
150
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' ) ) ;
151
154
} else if ( categoryKey && algorithmKey ) {
152
155
return AlgorithmApi . getAlgorithm ( categoryKey , algorithmKey )
153
156
. then ( ( { algorithm } ) => this . props . setAlgorithm ( algorithm ) ) ;
You can’t perform that action at this time.
0 commit comments