<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _url_for(endpoint: str, **values) -> Union[str, None]: """ The same as flask's url_for, except this also supports building external urls for hosts that are different from app.config.SERVER_NAME. One case where this is especially useful is for single page apps, where the frontend is not hosted by the same server as the backend, but the backend still needs to generate urls to frontend routes :param endpoint: the name of the endpoint :param values: the variable arguments of the URL rule :return: a url path, or None """

    _external_host = values.pop('_external_host', None)
    is_external = bool(_external_host or values.get('_external'))
    external_host = _external_host or current_app.config.get('EXTERNAL_SERVER_NAME')
    if not is_external or not external_host:
        return flask_url_for(endpoint, **values)

    if '://' not in external_host:
        external_host = f'http://{external_host}'
    values.pop('_external')
    return external_host.rstrip('/') + flask_url_for(endpoint, **values)