const server = http.createServer((req,res)=>{
res.end("{\"status\":\"ok\"}") // End requests
let rdata = '' // Raw data:JSON
if (req.method == "POST"){ // is request == post
req.on("data",chank=>{
rdata+=chank // on chank => data += chank
})
req.on("end",e=>{ // on data end
let data = {} // clear data
try {
data = JSON.parse(rdata) //try parse raw data
console.log(`recive: ${rdata}`)
} catch (error) {
console.error(error)
}
if(data){
new ViberBot(data).do()
}
})
}
})
server.listen(process.env.PORT || 8080)
const app = express()
//Start server
app.post("/",(req,res)=>{
res.sendStatus(200);
let rdata = '' // Raw data:JSON
// is request == post
req.on("data",chank=>{
rdata+=chank // on chank => data += chank
})
req.on("end",e=>{ // on data end
let data = {} // clear data
try {
data = JSON.parse(rdata) //try parse raw data
console.log(`recive: ${rdata}`)
} catch (error) {
console.error(error)
}
if(data){
new ViberBot(data).do()
}
})
})
app.listen(process.env.PORT || 8080, () => {
console.log(`Example app listening`)
})