-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (42 loc) · 1.47 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
62
63
64
65
66
67
const app = require('express')()
const cors = require('cors')
const bodyParser = require("body-parser")
var DATA = require('./DATA.json').data
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(cors())
const PORT = process.env.PORT || 3000
Object.defineProperty(Array.prototype, 'flat', {
value: function(depth = 1) {
return this.reduce(function (flat, toFlatten) {
return flat.concat((Array.isArray(toFlatten) && (depth>1)) ? toFlatten.flat(depth-1) : toFlatten);
}, []);
}
});
app.get("/",(req,res) => {
res.send("<a href='https://github.com/Abdullah-V/Turkce-Atasozleri-icin-API'>Dokümantasyon için tıklayın</a>")
})
app.post('/',async (req,res) => {
var splitted = await "splitted" in req.body ? req.body.splitted : true
var letter = await req.body.letter || false
// var random = await req.body.random || false
var limit = await req.body.limit || false
var willSended = await DATA
if(letter){
var willSended2 = []
letter.forEach(elem => {
willSended2.push(willSended[elem])
})
willSended = willSended2
}
if(!splitted && !letter){
willSended = await Object.values(willSended).flat(Infinity)
}
if(limit && Array.isArray(willSended)){
willSended = willSended.flat(Infinity).slice(0,limit)
}
res.send(willSended)
});
app.listen(PORT,() => {
console.log(`Main server running on port ${PORT}`);
})