@@ -28,30 +28,34 @@ router.get("/", function (req, res) {
28
28
headers : {
29
29
"User-Agent" : rua ,
30
30
} ,
31
- } ) . then ( function ( response ) {
32
- $ = cheerio . load ( response . data ) ;
31
+ } )
32
+ . then ( function ( response ) {
33
+ $ = cheerio . load ( response . data ) ;
33
34
34
- if ( dutchRandomWord . length > 0 ) {
35
- dutchRandomWord = [ ] ;
36
- }
37
- let post = $ ( "#output > div" ) ;
38
- let word = post . find ( `div:nth-child(${ rand } ) > h3` ) [ 0 ] . children [ 0 ] . data ;
39
- let definition = post
40
- . find ( `div:nth-child(${ rand } ) > span` ) [ 0 ]
41
- . children [ 0 ] . data . replace ( "Meaning: " , "" ) ;
42
- let pronunciation = pronounce ( word ) ;
43
- dutchRandomWord . push ( {
44
- word : decodeURI ( word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) ) ,
45
- definition : decodeURI (
46
- definition . charAt ( 0 ) . toUpperCase ( ) + definition . slice ( 1 )
47
- ) ,
48
- pronunciation : decodeURI (
49
- pronunciation . charAt ( 0 ) . toUpperCase ( ) + pronunciation . slice ( 1 )
50
- ) ,
35
+ if ( dutchRandomWord . length > 0 ) {
36
+ dutchRandomWord = [ ] ;
37
+ }
38
+ let post = $ ( "#output > div" ) ;
39
+ let word = post . find ( `div:nth-child(${ rand } ) > h3` ) [ 0 ] . children [ 0 ] . data ;
40
+ let definition = post
41
+ . find ( `div:nth-child(${ rand } ) > span` ) [ 0 ]
42
+ . children [ 0 ] . data . replace ( "Meaning: " , "" ) ;
43
+ let pronunciation = pronounce ( word ) ;
44
+ dutchRandomWord . push ( {
45
+ word : decodeURI ( word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) ) ,
46
+ definition : decodeURI (
47
+ definition . charAt ( 0 ) . toUpperCase ( ) + definition . slice ( 1 )
48
+ ) ,
49
+ pronunciation : decodeURI (
50
+ pronunciation . charAt ( 0 ) . toUpperCase ( ) + pronunciation . slice ( 1 )
51
+ ) ,
52
+ } ) ;
53
+ console . log ( dutchRandomWord ) ;
54
+ res . send ( JSON . stringify ( dutchRandomWord , null , 2 ) ) ;
55
+ } )
56
+ . catch ( ( error ) => {
57
+ console . log ( error . response ) ;
51
58
} ) ;
52
- console . log ( dutchRandomWord ) ;
53
- res . send ( JSON . stringify ( dutchRandomWord , null , 2 ) ) ;
54
- } ) ;
55
59
} ) ;
56
60
57
61
module . exports = router ;
0 commit comments