Skip to content

Commit 6fb6740

Browse files
committed
NEW API - Get Pronunciation for a Word
1 parent a716687 commit 6fb6740

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

README.md

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

1212
- Free API - `https://random-words-api.vercel.app/word`
1313
- Dutch Random Words - `https://random-words-api.vercel.app/word/dutch`
14+
- Get Pronunciation for a Word - `http://localhost:3000/word/pronounce/hello%20world`
1415

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

@@ -56,6 +57,12 @@
5657
]
5758
```
5859

60+
## 🌐 Sample Pronunciation Response
61+
62+
```json
63+
"helo worlt"
64+
```
65+
5966
## 💡 Learn New word
6067

6168
- [Join Telegram Channel](https://t.me/learnwordoftheday)

index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,28 @@ const app = express();
44
import home from './routes/home.js';
55
import en from './routes/en.js';
66
import dutch from './routes/dutch.js';
7+
import pronounce from './routes/pronounce.js';
78

89
app.use('/', home);
910
app.use('/word/dutch', dutch);
11+
app.use('/word/pronounce', pronounce);
1012
app.use('/word', en);
1113

14+
app.use('/', function(req, res) {
15+
res.status(404).json({
16+
error: 1,
17+
message: 'Page or Data not Found'
18+
});
19+
})
20+
21+
app.use((err, req, res, next) => {
22+
if (!err) return next();
23+
return res.status(403).json({
24+
error: 1,
25+
message: 'Page or Data not Found'
26+
});
27+
});
28+
1229
var port = process.env.PORT || 3000;
1330
app.listen(port, function() {
1431
console.log('listening on port ' + port);

routes/pronounce.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import express from "express";
2+
import { pronounce } from "node-pronounce";
3+
const router = express.Router();
4+
5+
router.get("/:word", function (req, res) {
6+
res.header("Access-Control-Allow-Origin", "*");
7+
res.header('Access-Control-Allow-Headers', 'Access-Control-Allow-Headers,Content-Type,Access-Control-Allow-Methods, Authorization, X-Requested-With');
8+
res.header("Access-Control-Allow-Methods", "GET");
9+
res.header("X-Frame-Options", "DENY");
10+
res.header("X-XSS-Protection", "1; mode=block");
11+
res.header("X-Content-Type-Options", "nosniff");
12+
res.header("Strict-Transport-Security", "max-age=63072000");
13+
res.setHeader("Content-Type", "application/json");
14+
15+
var userword = encodeURIComponent(req.params.word) || "Automation";
16+
let wordData = pronounce(userword);
17+
var pronouncedWord = decodeURIComponent(wordData);
18+
res.status(200).json(pronouncedWord);
19+
20+
});
21+
22+
export default router;

0 commit comments

Comments
 (0)