-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
86 lines (62 loc) · 1.99 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const cors = require('cors')
var express = require("express");
const bodyParser = require('body-parser');
var app = express();
var axios = require('axios');
const abcd=require('./abcd');
app.use(cors());
app.options('*', cors());
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Headers", "*");
next();
});
app.use(bodyParser.urlencoded({ extended: false }))
// app.use(bodyParser.json())
var cricData = require('cric-player-info');
const { response } = require("express");
app.use(express.static('public'));
app.use('/css', express.static(__dirname + '/public/css'));
app.use('/js', express.static(__dirname + '/public/js'));
app.use('/Home', express.static(__dirname + '/public/Home'));
// will get matching player name
app.post('/getplayernames', (req, res) => {
console.log(req.body.input)
cricData.getMatchingPlayerNames(req.body.input).then((response) => {
res.json({
names: response
})
})
})
// will return the stats of searched player
app.post('/getplayerinfo', (req, res) => {
console.log(req.body.playername)
abcd.getPlayerInfoByName(req.body.playername).then((response => {
console.log(JSON.stringify(response));
res.json({
info: response,
})
}));
})
app.post('/getplayerbatinfo', (req, res) => {
console.log(req.body.playername)
abcd.getPlayerBatInfoByName(req.body.playername).then((response => {
console.log(JSON.stringify(response));
res.json({
info: response,
})
}));
})
app.post('/getplayerbowlinfo', (req, res) => {
console.log(req.body.playername)
abcd.getPlayerBowlInfoByName(req.body.playername).then((response => {
console.log(JSON.stringify(response));
res.json({
info: response,
})
}));
})
var port = process.env.PORT || 8081
app.listen(port, function () {
console.log("Server started at http://localhost:%s", port)
});