Changing endpoints and handling in JS