title: Returning the output of an async function in a Hapi route handler
body: <p>I'm working on a Twitch extension if anyone's familiar and started working off of one of their examples. I'm fairly new to JS with mostly a C# background so a lot of this is kinda foreign to me. Basically I've setup a hapi route and want my node server to make an API call to a different service and return a string that includes some of the data from the API response, which then gets inserted to an iFrame using an AJAX request. The API wrapper that I'm using uses async functions and when I call them inside the route handler the requests seem to time out from what I can tell from looking at the request in chrome's devtools. Not sure if the API calls are just taking too long or something along those lines? Here's a link to the API wrapper I'm using: <a href="https://www.npmjs.com/package/smashgg.js?activeTab=readme" rel="nofollow noreferrer">https://www.npmjs.com/package/smashgg.js?activeTab=readme</a></p>
  
  <p>I suspect I'm missing something with the async/await syntax, I don't really fully understand how they work yet. Ideally I'd like to have the code that returns the output string in it's own method but for simplicity I've just copied the example but I'm getting the same results. This code runs fine in its own file.</p>
  
  <p>Here's the route definition:</p>
  
  <pre><code>  server.route({
      method: 'GET',
      path: '/bracket/query',
      handler: bracketQueryHandler
    });
  </code></pre>
  
  <p>and the route handler method:</p>
  
  <pre><code>async function bracketQueryHandler(req){
    const payload = verifyAndDecode(req.headers.authorization);
    const { channel_id: channelId, opaque_user_id: opaqueUserId } = payload;
    const currentBracket = channelBrackets[channelId] || initialBracket;
  
    let tournamentSlug = 'function-1-recursion-regional';
    let eventSlug = 'melee-singles';
    let meleeAtFunction = await Event.get(tournamentSlug, eventSlug);
  
    let sets = await meleeAtFunction.getSets();
    let phaseGroups = await meleeAtFunction.getPhaseGroups();
    let setString = "";
    for(var i in sets){
        setString += "\n" + sets[i].getFullRoundText() + " : " + sets[i].getDisplayScore();
    }
  
    console.log(setString);
    return setString;
  }
  </code></pre>