@@ -24,7 +24,73 @@ router.get("/", function (req, res) {
24
24
25
25
axios ( {
26
26
method : "GET" ,
27
- url : partOfSpeech ? `https://randomword.com/${ partOfSpeech } ` : `https://randomword.com` ,
27
+ url : 'https://randomword.com' ,
28
+ headers : {
29
+ "User-Agent" : rua ,
30
+ } ,
31
+ } )
32
+ . then ( function ( response ) {
33
+ $ = cheerio . load ( response . data ) ;
34
+ if ( wordOfDay . length > 0 ) {
35
+ wordOfDay = [ ] ;
36
+ }
37
+
38
+ var post = $ ( ".section #shared_section" ) ;
39
+ var word = post
40
+ . find ( "#random_word" )
41
+ . eq ( 0 )
42
+ . text ( )
43
+ . replace ( "\r\n\t\t\t\t\t" , "" )
44
+ . replace ( "\r\n\t\t\t\t" , "" )
45
+ . replace ( "\n\t\t\t\t\t" , "" )
46
+ . replace ( "\n\t\t\t\t" , "" ) ;
47
+ var definition = post
48
+ . find ( "#random_word_definition" )
49
+ . eq ( 0 )
50
+ . text ( )
51
+ . replace ( "\n" , "" ) ;
52
+ var pronounceword = pronounce ( word ) . replace ( "," , "" ) ;
53
+
54
+ wordOfDay . push ( {
55
+ word : decodeURI ( word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) ) ,
56
+ definition : decodeURI (
57
+ definition . charAt ( 0 ) . toUpperCase ( ) + definition . slice ( 1 )
58
+ ) ,
59
+ pronunciation : decodeURI (
60
+ pronounceword . charAt ( 0 ) . toUpperCase ( ) + pronounceword . slice ( 1 )
61
+ ) ,
62
+ } ) ;
63
+ res . send ( JSON . stringify ( wordOfDay , null , 2 ) ) ;
64
+ } )
65
+ . catch ( function ( error ) {
66
+ if ( ! error . response ) {
67
+ console . log ( "API URL is Missing" ) ;
68
+ res . json ( "API URL is Missing" ) ;
69
+ } else {
70
+ console . log ( "Something Went Wrong - Enter the Correct API URL" ) ;
71
+ res . json ( "Something Went Wrong - Enter the Correct API URL" ) ;
72
+ }
73
+ } ) ;
74
+ } ) ;
75
+
76
+ router . get ( "/:pos" , function ( req , res ) {
77
+
78
+ const partOfSpeech = req . params . pos ;
79
+ res . header ( "Access-Control-Allow-Origin" , "*" ) ;
80
+ res . header (
81
+ "Access-Control-Allow-Headers" ,
82
+ "Access-Control-Allow-Headers,Content-Type,Access-Control-Allow-Methods, Authorization, X-Requested-With"
83
+ ) ;
84
+ res . header ( "Access-Control-Allow-Methods" , "GET" ) ;
85
+ res . header ( "X-Frame-Options" , "DENY" ) ;
86
+ res . header ( "X-XSS-Protection" , "1; mode=block" ) ;
87
+ res . header ( "X-Content-Type-Options" , "nosniff" ) ;
88
+ res . header ( "Strict-Transport-Security" , "max-age=63072000" ) ;
89
+ res . setHeader ( "Content-Type" , "application/json" ) ;
90
+
91
+ axios ( {
92
+ method : "GET" ,
93
+ url : `https://randomword.com/${ partOfSpeech } ` ,
28
94
headers : {
29
95
"User-Agent" : rua ,
30
96
} ,
0 commit comments