Also noticing some strange behavior in that <https...
# prisma-whats-new
m
Also noticing some strange behavior in that https://tehsis.github.io/webtaskio-canirequire/#axios shows axios is available but when i require it is undefined unlike in the validator which comes in fine just like in the example video.
n
you can now require all node modules, and logging modules is known to show
{}
but it still works
m
yeah axios is coming in undefined though
n
should still work
m
Copy code
const axios = require('axios');
module.exports = function (event) {
  const GEOCODE_API = '<https://maps.googleapis.com/maps/api/geocode/json?>';
  const API_KEY     = 'key=MyKEY';
  const STREET      = event.data.street;
  const CITY        = event.data.city;
  const STATE       = event.data.state;
  const ZIP         = event.data.zip;
  const ADDRESS_KEY = 'address=' + STREET + '%20' + CITY + '%2C%20' + STATE + '%20' + ZIP;
  const URL = GEOCODE_API + API_KEY + '&' + ADDRESS_KEY;
  // Need to geocode and set lat and long
  event.data.lat = 38.96265898029149;
  event.data.lng = -76.9389200197085;

  axios.get(URL)
  .then(function (response) {
    console.log(response);
  	return { data: event.data }
  })
  .catch(function (error) {
    console.log(error);
  	return { data: event.data }
  });
}
nothing in the then or catch executes
n
you need to say
return axios...
❤️ 1
m
oh got it so it is not executing the promise. I need to return it?
n
ya
m
Awesome thank you that worked!
🎉 1
n
ya there's some things that you need to get used to like returning promises
or wrapping callbacks
hope browsing the examples helps
pretty explicit sorry I didn't see that earlier
Oh geez really sorry there is literally an example in the repo of exactly what I am doing. I will be sure to check there first from now on. Sorry!! https://github.com/graphcool-examples/functions/blob/master/directions-and-geocoding/google-geocoding/google-geocoding.js
n
😄 you don't have to be sorry!
m
Kind of related to this I was going to restrict the key will all outbound requests like this be coming from the same domain? Doesn't matter too much since this is being done on the server though I guess.