File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,7 +20,10 @@ const cache = new LRUCache({
2020 max : maxRows
2121} ) ;
2222
23- const extra = { id : 0 , message : "Additional fortune added at request time." } ;
23+ const extra = ( ) => ( {
24+ id : 0 ,
25+ message : "Additional fortune added at request time."
26+ } ) ;
2427
2528const app = express ( ) ;
2629
@@ -65,7 +68,7 @@ if (db) {
6568
6669 app . get ( "/fortunes" , async ( req , res ) => {
6770 const rows = await db . fortunes ( ) ;
68- rows . push ( extra ) ;
71+ rows . push ( extra ( ) ) ;
6972 rows . sort ( ( a , b ) => ( a . message < b . message ) ? - 1 : 1 ) ;
7073 const n = rows . length ;
7174 let html = "" ,
@@ -126,4 +129,4 @@ const port = parseInt(process.env.PORT || "8080");
126129const server = app . listen ( port , host , ( ) => {
127130 console . log ( `Server running at http://${ host } :${ port } /` ) ;
128131} ) ;
129- server . keepAliveTimeout = 0 ;
132+ server . keepAliveTimeout = 0 ;
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ module.exports = (databaseLayer) => ({
2727 fortunes : async ( req , reply ) => {
2828 const fortunes = await databaseLayer . allFortunes ( ) ;
2929
30- fortunes . push ( h . additionalFortune ) ;
30+ fortunes . push ( h . additionalFortune ( ) ) ;
3131 fortunes . sort ( compare ) ;
3232
3333 return reply . view ( "/views/fortunes.hbs" , { fortunes } ) ;
Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ module.exports = {
55 return Math . min ( Math . max ( parseInt ( queries ) || 1 , 1 ) , 500 ) ;
66 } ,
77
8- additionalFortune : {
8+ additionalFortune : ( ) => ( {
99 id : 0 ,
1010 message : "Additional fortune added at request time." ,
11- } ,
11+ } ) ,
1212} ;
Original file line number Diff line number Diff line change 2626 } ) ;
2727
2828if ( db ) {
29- const extra = { id : 0 , message : "Additional fortune added at request time." } ;
29+ const extra = ( ) => ( {
30+ id : 0 ,
31+ message : "Additional fortune added at request time."
32+ } ) ;
3033
3134 app
3235 . get ( "/db" , async ( c ) => {
@@ -49,7 +52,7 @@ if (db) {
4952 return c . json ( worldObjects ) ;
5053 } )
5154 . get ( "/fortunes" , async ( c ) => {
52- const rows = [ extra , ...( await db . fortunes ( ) ) ] ;
55+ const rows = [ extra ( ) , ...( await db . fortunes ( ) ) ] ;
5356
5457 sortByMessage ( rows ) ;
5558
Original file line number Diff line number Diff line change 11const db = require ( '../db' )
22const { escape } = require ( 'html-escaper' )
33
4- const runTimeFortune = {
4+ const runTimeFortune = ( ) => ( {
55 id : 0 ,
66 message : 'Additional fortune added at request time.'
7- }
7+ } )
88
99function sortByMessage ( arr ) {
1010 const n = arr . length
@@ -23,9 +23,9 @@ function sortByMessage(arr) {
2323module . exports = {
2424 GET : async ( { res } ) => {
2525 let fortunes = await db . allFortunes ( )
26- fortunes . push ( runTimeFortune )
26+ fortunes . push ( runTimeFortune ( ) )
2727 sortByMessage ( fortunes )
28-
28+
2929 let html = '<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>' ;
3030 for ( let i = 0 ; i < fortunes . length ; i ++ ) {
3131 html += `<tr><td>${ fortunes [ i ] . id } </td><td>${ escape ( fortunes [ i ] . message ) } </td></tr>` ;
Original file line number Diff line number Diff line change @@ -93,15 +93,18 @@ if (db) {
9393 }
9494 } ) ;
9595
96- const extra = { id : 0 , message : "Additional fortune added at request time." } ;
96+ const extra = ( ) => ( {
97+ id : 0 ,
98+ message : "Additional fortune added at request time."
99+ } ) ;
97100
98101 webserver . get ( "/fortunes" , async ( response ) => {
99102 response . onAborted ( ( ) => {
100103 response . aborted = true ;
101104 } ) ;
102105
103106 try {
104- const rows = [ extra , ...await db . fortunes ( ) ] ;
107+ const rows = [ extra ( ) , ...await db . fortunes ( ) ] ;
105108
106109 if ( response . aborted ) {
107110 return ;
You can’t perform that action at this time.
0 commit comments