I think you were intending to use port instead of window.location.port here.