     res.header 'Access-Control-Allow-Origin', '*'
     res.json stgrSays: 'serving test!'
 
-  recentlyChanged: (req, res) ->
+  lastChange: (req, res) ->
     console.log '\nOMG, a request!'
     console.info 'request made for:\n' + req.url
 

  if changedCount
    console.log '\nnew branches!'

    recentlyChanged = true
    serverResults   = newResults

    fetchMilestones (activeMilestones) ->
      addGithubData changedServers, changedCount, activeMilestones

initQuery = ->
  t = setInterval ->
    do queryServers
  , queryInterval

  do queryServers

###
iterate through the staging servers and hand off to be checked
###
queryServers = ->
  console.log '\nquerying staging servers'

  newResults = {}
  serverCount = serverList.length

  _.each serverList, (server) ->
    queryServer server, (currentBranch) ->
      if currentBranch
        newResults[server] = currentBranch
      else
        serverCount--;

      if _.keys(newResults).length is serverCount
        do printLineBreak
        devLog newResults

        compareResults newResults

###
ask each staging server what branch they're running
###
queryServer = (server, callback = ->) ->
  # console.log '\nquerying server:\n' + server
  maxAttempts   = 10
  connAttempts  = 0

  # test for forward or backward slashes, aka things that shouldn't be in a branch
  # if found, rerun branch check
  validateResponse = (response) ->
    response = if response.length then response.pop().split('Pinnaclebranch:')[1].split('Contrabranch:')[0] else 'logout'

    unless /\\|\/|logout|HEAD/.test response
      callback response
    else if connAttempts >= maxAttempts
      callback false
    else
      do printLineBreak
      console.info 'uh-oh, SSH branch check ' + connAttempts + ' of ' + maxAttempts + ' for server ' + server + ' returned bad data\ntrying again'

      do doQueryServer

  doQueryServer = ->
    connAttempts++;

    conn = new SSH()

    conn.on 'ready', ->
      conn.shell 'echo "test"', (err, stream) ->
        throw err if err

        output = []

        stream.stderr.on 'data', (data) ->
          console.error 'STDERR: ' + data

        stream.on 'data', (data) ->
          data = data.toString('utf8').replace /\s/g, ''

          # remove
          return false if data.length < 2 or /^\[|Nosuchfileordirectory/.test data

          # if the following command gets lumped in with the current line's output, cut it out
          data = data.split(/\[/)[0] if /\[/.test data

          output.push data if /Pinnaclebranch/.test data

        stream.on 'close', ->
          do conn.end

          # do printLineBreak
          # devLog server + ' responded:'
          # do printLineBreak
          # devLog currentBranch

          validateResponse output

        stream.end 'cat /tmp/' + server.split('.')[1].toUpperCase() + '_CURRENT_BRANCHES\nexit\n'

    conn.connect
      host: server
      port: 22
      username: 'ec2-user'
      privateKey: file.readFileSync '/Users/bradmallow/Documents/keys/dops-dev.pem'

  # initial server query
  do doQueryServer

###
check to see if any servers have changed
###
compareResults = (newResults) ->
  console.log '\ncomparing results'

