Improve logic for building /api/sync URL from ws:// url