refactor server connection into a require.js module