`url.resolve` will replace anything after the last `/` with the second argument, so it's imperative to ensure that `basePath` has a trailing slash. The call to `replace` adds one unless it already exists.