public static function enableCORS($origin='*'){

        // Allow from any origin
        if ($origin = $origin ?:( isset($_SERVER['HTTP_ORIGIN'])
                    ? $_SERVER['HTTP_ORIGIN']
                    : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '*')
        )) {
          static::header('Access-Control-Allow-Origin',      $origin);
          static::header('Access-Control-Allow-Credentials', 'true');
          static::header('Access-Control-Max-Age',           86400);
        }

        // Access-Control headers are received during OPTIONS requests
        if (filter_input(INPUT_SERVER,'REQUEST_METHOD') == 'OPTIONS') {
            static::clean();

            if (filter_input(INPUT_SERVER,'HTTP_ACCESS_CONTROL_REQUEST_METHOD')) {
              static::header('Access-Control-Allow-Methods',
                'GET, POST, PUT, DELETE, OPTIONS, HEAD, CONNECT, PATCH, TRACE');
            }
            if ($req_h = filter_input(INPUT_SERVER,'HTTP_ACCESS_CONTROL_REQUEST_HEADERS')) {
              static::header('Access-Control-Allow-Headers',$req_h);
            }

            self::trigger('cors.preflight');
            static::send();
            exit;
        }
    }