-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (51 loc) · 1.48 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const PORT = 8000
const axios = require('axios');
const express = require("express")
const cors = require('cors')
require('dotenv').config()
const app = express()
app.use(cors())
app.get('/word',(req,res) => {
const options = {
method: 'GET',
url: 'https://random-words5.p.rapidapi.com/getMultipleRandom',
params: {
count: '5',
wordLength: '5'
},
headers: {
'X-RapidAPI-Key': process.env.RAPID_API_KEY,
'X-RapidAPI-Host': 'random-words5.p.rapidapi.com'
}
};
try {
axios.request(options).then((response) => {
console.log(response.data);
res.json(response.data[0])
})
} catch (error) {
console.error(error);
}
})
app.get('/check',(req,res) => {
const currword = req.query.currword
// console.log(req)
const options = {
method: 'GET',
url: 'https://dictionary-by-api-ninjas.p.rapidapi.com/v1/dictionary',
params: {word: currword},
headers: {
'X-RapidAPI-Key': process.env.RAPID_API_KEY,
'X-RapidAPI-Host': 'dictionary-by-api-ninjas.p.rapidapi.com'
}
};
try {
axios.request(options).then((response) =>{
console.log(response.data);
res.json(response.data.valid)
})
} catch (error) {
console.error(error);
}
})
app.listen(PORT, () => console.log('Server started on port '+PORT))