Skip to content

Commit 0150fa2

Browse files
committed
feat(docs): ✨ add swagger docs
1 parent dd54e56 commit 0150fa2

File tree

10 files changed

+375
-14
lines changed

10 files changed

+375
-14
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ OR
121121
Project - Give Forked Repo URL - Go Live
122122
```
123123

124+
## 🔐 Rate Limit
125+
126+
- To configure the rate limit, edit the `utils/index.js` file
127+
- Look for `limiter` variable
128+
- `max` is the maximum number of requests allowed in a given time window
129+
- `windowMs` is the time window in milliseconds
130+
- `message` is the message to be returned when the rate limit is exceeded
131+
124132
## 😇 Add New Language
125133
- Create a new folder in `data` with the full language name `ex: english`
126134
- Add the words in the `words.json` file

app.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "wotd",
3-
"description": "Word of the Day.",
2+
"name": "random-words-api",
3+
"description": "API for getting random words in different languages",
44
"repository": "https://github.com/mcnaveen/Random-Words-API",
5-
"keywords": ["expressjs", "nodejs", "json"]
5+
"keywords": ["expressjs", "nodejs", "json", "random-words", "api"]
66
}

index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
import express from "express";
22
const app = express();
33

4-
import home from './routes/home.js';
54
import english from './routes/english.js';
65
import language from './routes/language.js';
6+
import swaggerUi from './swagger-ui.js';
7+
import { limiter } from "./utils/index.js";
78

8-
app.use('/', home);
9+
// Apply rate limiter to all routes except root
10+
app.use((req, res, next) => {
11+
if (req.path !== '/') {
12+
return limiter(req, res, next);
13+
}
14+
next();
15+
});
16+
17+
app.use('/', swaggerUi);
918
app.use('/word', english);
1019
app.use('/word', language);
20+
app.use('/api-docs', swaggerUi);
1121

1222
app.use('/', function(_req, res) {
1323
res.status(404).json({

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
{
2-
"name": "wotd",
2+
"name": "random-words-api",
33
"version": "1.0.0",
4-
"description": "Word of the Day",
4+
"description": "API for getting random words in different languages",
55
"private": true,
66
"main": "index.js",
77
"dependencies": {
88
"axios": "^1.1.3",
99
"cheerio": "^1.0.0-rc.12",
1010
"express": "^4.18.2",
11+
"express-rate-limit": "^7.4.0",
1112
"node-pronounce": "^0.0.4",
1213
"random-array-item": "^0.0.2",
13-
"random-useragent": "^0.5.0"
14+
"random-useragent": "^0.5.0",
15+
"swagger-jsdoc": "^6.2.8",
16+
"swagger-ui-express": "^5.0.1"
1417
},
1518
"scripts": {
1619
"test": "echo \"Error: no test specified\" && exit 1",

0 commit comments

Comments
 (0)