move resolveEndpoint to util.js