Skip to content

Commit edefcbe

Browse files
committed
added parts of speech to home route and updated readme
1 parent 2ab34cf commit edefcbe

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,25 @@
1111

1212
- PWA Demo - [Check Here](https://words.sanweb.info/)
1313

14+
## 🎛 Route Options
15+
16+
- Base URL: `https://random-words-api.vercel.app/word`
17+
```html
18+
- /noun
19+
- /sentence
20+
- /question
21+
- /adjective
22+
- /idiom
23+
- /verb
24+
- /letter
25+
- /paragraph
26+
- /vocabulary
27+
- /1-word-quotes
28+
- /2-word-quotes
29+
- /3-word-quotes
30+
- /affirmation
31+
```
32+
1433
## 🌐 Sample API Response
1534

1635
```json

routes/en.js

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,73 @@ router.get("/", function (req, res) {
2424

2525
axios({
2626
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}`,
2894
headers: {
2995
"User-Agent": rua,
3096
},

0 commit comments

Comments
 (0)