Use window.location.origin instead of hard coding localhost