Do not hard code localhost. Use window.location.hostname instead.