server-app: make _sortLayersByPhase stable

Fix the phase-sorting algorithm to use a stable sorting algorithm,
since the built-in `Array.prototype.sort` is not stable.
Merge pull request #925 from strongloop/fix/stable-sort-for-middleware

server-app: make _sortLayersByPhase stable