require("request/package.json");
var express = require("@runkit/runkit/express-endpoint/1.0.0");
var requestPromise = require("request-promise"),
youtubedl = require('youtube-dl'),
mcache = require( 'memory-cache'),
app = express(module.exports)
// const app = express()
/** CONFIG **/
const port = process.env.PORT || 4000
const requestCache = (duration) => {
return (req, res, next) => {
let key = `__express__${req.originalUrl}` || req.url
let cachedBody = mcache.get(key)
if (cachedBody) {
res.send(cachedBody)
} else {
res.sendResponse = res.send
res.send = (body) => {
mcache.put(key, body, duration)
res.sendResponse(body)
}
next()
}
}
}
/** ROUTES **/
/* home */
app.get('/', (req, res) => {
const text = '<h1>Soccer Betting API project</h1><p>All Soccer Matches <a href="https://soccer-jbfpjup0bgpc.runkit.sh/match" target="_blank">Matches</a>. </p><br><p>getMatchDetail <a href="https://soccer-jbfpjup0bgpc.runkit.sh/match/1732936" target="_blank">Matches exampleId :1732936</a>.</p>'
res.send(text)
})
app.get('/match/:id', (req, res) => {
var ids = req.params.id;
var getMatch = {
id: ids,
_ApplicationId: "d93305fc-b7fb-4b4f-9b36-23f8319a9588",
_ClientVersion: "js2.2.1",
_InstallationId: "bcb2536c-2f30-05cb-9b90-36f4863b872b"
}
requestPromise("https://www.bhawlone.com/parse/functions/getMatchDetail",
{
"credentials":"include",
"headers":
{
"accept":"*/*","accept-language":"en-GB,en;q=0.9,en-US;q=0.8,my;q=0.7",
"content-type":"application/json"
},
"referrer":"https://www.bhawlone.com/",
"referrerPolicy":"no-referrer-when-downgrade",
"body":JSON.stringify(getMatch),
"method":"POST",
"mode":"cors"
}).then(response => JSON.parse(response))
.then(data => res.send(data.result))
.catch(error => console.error('Error:', error));
});
app.get('/match', (req, res) => {
var getMatch = {
bookmaker_id: "3",
_ApplicationId: "d93305fc-b7fb-4b4f-9b36-23f8319a9588",
_ClientVersion: "js2.2.1",
_InstallationId: "bcb2536c-2f30-05cb-9b90-36f4863b872b"
}
requestPromise("https://www.bhawlone.com/parse/functions/getMatches",
{
"credentials":"include",
"headers":
{
"accept":"*/*","accept-language":"en-GB,en;q=0.9,en-US;q=0.8,my;q=0.7",
"content-type":"application/json"
},
"referrer":"https://www.bhawlone.com/",
"referrerPolicy":"no-referrer-when-downgrade",
"body":JSON.stringify(getMatch),
"method":"POST",
"mode":"cors"
}).then(response => JSON.parse(response))
.then(data => res.send(data.result))
.catch(error => console.error('Error:', error));
});
/** LISTEN **/
app.listen(port)
console.log(`Listening on: ${port}`)