Skip to content

Commit 3105910

Browse files
authored
Merge pull request #81 from mskian/main
feat(route): ✨ Add Pronounce Route to API
2 parents a716687 + 2d17f70 commit 3105910

File tree

10 files changed

+397
-22
lines changed

10 files changed

+397
-22
lines changed

.all-contributorsrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
"avatar_url": "https://avatars.githubusercontent.com/u/8493007?v=4",
1212
"profile": "https://github.com/mcnaveen",
1313
"contributions": [
14+
"bug",
1415
"code",
1516
"data",
1617
"doc",
18+
"example",
1719
"ideas",
1820
"maintenance",
1921
"review"
@@ -49,5 +51,6 @@
4951
"projectOwner": "mcnaveen",
5052
"repoType": "github",
5153
"repoHost": "https://github.com",
52-
"skipCi": true
54+
"skipCi": true,
55+
"commitConvention": "none"
5356
}

.vercelignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ test.js
1212
app.js
1313
renovate.json
1414
proxy.js
15-
.env
15+
.env
16+
test

README.md

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Random Words API
2+
23
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
3-
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-)
4+
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-)
45
<!-- ALL-CONTRIBUTORS-BADGE:END -->
56

67
![build-test](https://github.com/mcnaveen/Random-Words-API/workflows/build-test/badge.svg)
@@ -11,13 +12,15 @@
1112

1213
- Free API - `https://random-words-api.vercel.app/word`
1314
- Dutch Random Words - `https://random-words-api.vercel.app/word/dutch`
15+
- Get Pronunciation for a Word - `https://random-words-api.vercel.app/pronounce/`
1416

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

1719
## 🎛 Route Options
1820

1921
- Base URL: `https://random-words-api.vercel.app/word`
20-
```html
22+
23+
```text
2124
- /noun
2225
- /sentence
2326
- /question
@@ -35,6 +38,9 @@
3538

3639
## 🌐 Sample API Response
3740

41+
- API: `https://random-words-api.vercel.app/word/`
42+
- Method: `GET`
43+
3844
```json
3945
[
4046
{
@@ -46,6 +52,10 @@
4652
```
4753

4854
## 🌐 Sample Dutch Response
55+
56+
- API: `https://random-words-api.vercel.app/word/dutch`
57+
- Method: `GET`
58+
4959
```json
5060
[
5161
{
@@ -56,6 +66,30 @@
5666
]
5767
```
5868

69+
## 🌐 Sample Pronunciation Request
70+
71+
- API: `https://random-words-api.vercel.app/pronounce`
72+
- Method: `POST`
73+
74+
```sh
75+
POST http://localhost:3000/pronounce
76+
Content-Type: application/json
77+
78+
{
79+
"word": "This is amazing"
80+
}
81+
```
82+
83+
## 📣 Sample Pronunciation Response
84+
85+
```json
86+
{
87+
"pronunciation": "this is amasink"
88+
}
89+
```
90+
91+
- Check [api.rest](/test/api.rest) file for more details
92+
5993
## 💡 Learn New word
6094

6195
- [Join Telegram Channel](https://t.me/learnwordoftheday)
@@ -81,42 +115,50 @@ yarn start
81115

82116
OneClick Deploy on Heroku
83117

84-
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/mcnaveen/Random-Words-API)
118+
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/mcnaveen/Random-Words-API)
85119

86120
## 🔀 Deploying to Vercel
87121

88122
OneClick Deploy on Vercel
89123

90-
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2Fmcnaveen%2FRandom-Words-API.git)
124+
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2Fmcnaveen%2FRandom-Words-API.git)
91125

92126
OR
93127

94128
```html
95129
- Fork the Repo
96130
- Login to Vercel (https://vercel.com/dashboard)
97131
- Click Import Project
98-
- Give Forked Repo URL
99-
- Go Live
132+
- Give Forked Repo URL - Go Live
100133
```
101134

102-
## ✍️ Commit
135+
## :question: How to Contribute?
136+
137+
Make your changes and follow the below instructions. We follow conventional commits.
138+
139+
### ✍️ Commit
103140

104141
- Stage all changes
105-
```
142+
143+
```sh
106144
git add .
107-
```
108-
- Commit the changes
109145
```
146+
147+
- Commit the changes
148+
149+
```sh
110150
yarn commit
111151
```
152+
112153
- Push the changes to GitHub
113-
```
154+
155+
```sh
114156
git push <TO YOUR FORK>
115157
```
116158

117159
## ⚛ CREDITS
118160

119-
- Thanks to [Santhosh Veer](https://github.com/mskian) for Progressive Web APP - [Source Code](https://github.com/mskian/vue-random-words)
161+
- Thanks to [Santhosh Veer](https://github.com/mskian) for Progressive Web APP - [Source Code](https://github.com/mskian/vue-random-words)
120162

121163
## ☑ LICENSE
122164

@@ -139,6 +181,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
139181
<!-- markdownlint-disable -->
140182
<table>
141183
<tr>
184+
<td align="center"><a href="https://github.com/mcnaveen"><img src="https://avatars.githubusercontent.com/u/8493007?v=4?s=100" width="100px;" alt=""/><br /><sub><b>MC Naveen</b></sub></a><br /><a href="https://github.com/mcnaveen/Random-Words-API/issues?q=author%3Amcnaveen" title="Bug reports">🐛</a> <a href="https://github.com/mcnaveen/Random-Words-API/commits?author=mcnaveen" title="Code">💻</a> <a href="#data-mcnaveen" title="Data">🔣</a> <a href="https://github.com/mcnaveen/Random-Words-API/commits?author=mcnaveen" title="Documentation">📖</a> <a href="#example-mcnaveen" title="Examples">💡</a> <a href="#ideas-mcnaveen" title="Ideas, Planning, & Feedback">🤔</a> <a href="#maintenance-mcnaveen" title="Maintenance">🚧</a> <a href="https://github.com/mcnaveen/Random-Words-API/pulls?q=is%3Apr+reviewed-by%3Amcnaveen" title="Reviewed Pull Requests">👀</a></td>
142185
<td align="center"><a href="https://github.com/jonah-butler"><img src="https://avatars.githubusercontent.com/u/18040568?v=4?s=100" width="100px;" alt=""/><br /><sub><b>jonah-butler</b></sub></a><br /><a href="https://github.com/mcnaveen/Random-Words-API/commits?author=jonah-butler" title="Code">💻</a> <a href="https://github.com/mcnaveen/Random-Words-API/commits?author=jonah-butler" title="Documentation">📖</a></td>
143186
<td align="center"><a href="https://santhoshveer.com/"><img src="https://avatars.githubusercontent.com/u/10300271?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Santhosh Veer</b></sub></a><br /><a href="https://github.com/mcnaveen/Random-Words-API/commits?author=mskian" title="Code">💻</a> <a href="https://github.com/mcnaveen/Random-Words-API/commits?author=mskian" title="Documentation">📖</a> <a href="#ideas-mskian" title="Ideas, Planning, & Feedback">🤔</a> <a href="#maintenance-mskian" title="Maintenance">🚧</a> <a href="https://github.com/mcnaveen/Random-Words-API/issues?q=author%3Amskian" title="Bug reports">🐛</a> <a href="https://github.com/mcnaveen/Random-Words-API/pulls?q=is%3Apr+reviewed-by%3Amskian" title="Reviewed Pull Requests">👀</a></td>
144187
</tr>
@@ -149,4 +192,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
149192

150193
<!-- ALL-CONTRIBUTORS-LIST:END -->
151194

152-
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
195+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,27 @@ 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);
1011
app.use('/word', en);
12+
app.use('/pronounce', pronounce);
13+
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+
});
1128

1229
var port = process.env.PORT || 3000;
1330
app.listen(port, function() {

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
"scripts": {
1616
"test": "echo \"Error: no test specified\" && exit 1",
1717
"start": "node index.js",
18-
"action": "node test.js",
18+
"action": "node ./test/test.js",
1919
"dev": "nodemon index.js --ext '*'",
20-
"commit": "gacp"
20+
"commit": "gacp",
21+
"contributors:add": "all-contributors add",
22+
"contributors:generate": "all-contributors generate"
2123
},
2224
"type": "module",
2325
"keywords": [
@@ -37,6 +39,7 @@
3739
"author": "MC Naveen",
3840
"license": "MIT",
3941
"devDependencies": {
42+
"all-contributors-cli": "^6.20.0",
4043
"gacp": "^3.0.2",
4144
"nodemon": "^2.0.19"
4245
},

routes/pronounce.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import express from "express";
2+
import { pronounce } from "node-pronounce";
3+
const router = express.Router();
4+
5+
router.use(express.json());
6+
7+
router.post("/", function (req, res) {
8+
res.header("Access-Control-Allow-Origin", "*");
9+
res.header(
10+
"Access-Control-Allow-Headers",
11+
"Access-Control-Allow-Headers,Content-Type,Access-Control-Allow-Methods, Authorization, X-Requested-With"
12+
);
13+
res.header("Access-Control-Allow-Methods", "GET");
14+
res.header("X-Frame-Options", "DENY");
15+
res.header("X-XSS-Protection", "1; mode=block");
16+
res.header("X-Content-Type-Options", "nosniff");
17+
res.header("Strict-Transport-Security", "max-age=63072000");
18+
res.setHeader("Content-Type", "application/json");
19+
20+
var userWord = encodeURIComponent(req.body.word) || "Hello World";
21+
if (userWord == "undefined") {
22+
res.status(400).json({ pronunciation: "Empty data" });
23+
} else {
24+
let wordData = pronounce(userWord);
25+
const pronouncedWord = decodeURIComponent(wordData);
26+
res.status(200).json({ pronunciation: pronouncedWord });
27+
}
28+
});
29+
30+
export default router;

test/api.rest

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
POST http://localhost:3000/pronounce
2+
Content-Type: application/json
3+
4+
{
5+
"word": "This is amazing"
6+
}

proxy.js renamed to test/proxy.js

File renamed without changes.

test.js renamed to test/test.js

File renamed without changes.

0 commit comments

Comments
 (0)