var tonicExpress = require("@runkit/runkit/express-endpoint/1.0.0")
const axios = require('axios'); // promised based requests - like fetch()
const apitoken = 'POhW9bxB9a0wTN9ysAXj__TpOFvuyw4FEhfykgL9hfqmfnrIOiR-1eyCqiwAUq_IY5QbGKkWtodHMBYvFbCcfZDbMNw81-hdC_t0-MUdfvJq6xgz1Jqu6ESOWbDUWnYx'
function getBus(tokenStr) {
const AuthStr = 'Bearer '.concat(tokenStr);
return axios.get('https://api.yelp.com/v3/businesses/search?term=coffee&latitude=32.786882&longitude=-117.399972', { headers: { Authorization: AuthStr } })
}
// Just provide the exports object to the tonicExpress helper
var app = tonicExpress(module.exports)
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));
function getCoffee() {
return new Promise(resolve => {
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee
});
}
app.get("/", async (req, res) => {
try {
const bus = await getBus(apitoken);
// console.log(bus.data);
res.send(bus.data);
} catch (e) {
console.error(e); // 💩
}
})