Skip to content

Commit 313f7d5

Browse files
committed
add validation and test folder
1 parent 633b0b1 commit 313f7d5

File tree

7 files changed

+15
-11
lines changed

7 files changed

+15
-11
lines changed

.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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Content-Type: application/json
7171
}
7272
```
7373

74-
- Check [api.rest](/api.rest) file for more details
74+
- Check [api.rest](/test/api.rest) file for more details
7575

7676
## 💡 Learn New word
7777

@@ -117,19 +117,19 @@ Project - Give Forked Repo URL - Go Live
117117

118118
- Stage all changes
119119

120-
```
120+
```sh
121121
git add .
122122
```
123123

124124
- Commit the changes
125125

126-
```
126+
```sh
127127
yarn commit
128128
```
129129

130130
- Push the changes to GitHub
131131

132-
```
132+
```sh
133133
git push <TO YOUR FORK>
134134
```
135135

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
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 '*'",
2020
"commit": "gacp"
2121
},

routes/pronounce.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ router.post("/", function (req, res) {
1717
res.header("Strict-Transport-Security", "max-age=63072000");
1818
res.setHeader("Content-Type", "application/json");
1919

20-
var userWord = encodeURIComponent(req.body.word);
21-
let wordData = pronounce(userWord);
22-
const pronouncedWord = decodeURIComponent(wordData);
23-
res.status(200).json({ pronunciation: pronouncedWord });
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+
}
2428
});
2529

2630
export default router;

api.rest renamed to test/api.rest

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
## POST
21
POST http://localhost:3000/pronounce
32
Content-Type: application/json
43

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)