Bypass the normal handler and serve HTML for all URLs

    The ``app_path`` setting must be non-empty and the request must ask for
    ``text/html`` in the ``Accept`` header.

def html_override_tool():
    '''
    Bypass the normal handler and serve HTML for all URLs

    The ``app_path`` setting must be non-empty and the request must ask for
    ``text/html`` in the ``Accept`` header.
    '''
    apiopts = cherrypy.config['apiopts']
    request = cherrypy.request

    url_blacklist = (
        apiopts.get('app_path', '/app'),
        apiopts.get('static_path', '/static'),
    )

    if 'app' not in cherrypy.config['apiopts']:
        return

    if request.path_info.startswith(url_blacklist):
        return

    if request.headers.get('Accept') == '*/*':
        return

    try:
        wants_html = cherrypy.lib.cptools.accept('text/html')
    except cherrypy.HTTPError:
        return
    else:
        if wants_html != 'text/html':
            return

    raise cherrypy.InternalRedirect(apiopts.get('app_path', '/app'))