Riverbed Stingray steelapp,在维护页面上显示图像

时间:2014-06-27 09:47:54

标签: html stingray

我们已经在河床黄貂鱼上设置我们的应用程序,其中一个要求是当管理员想要更新系统时显示维护页面。

为此,我们创建了一个带有徽标图像的html页面,并将.html和.png图像上传到Extra File / miscellaneous路径。我们创建了一条规则,在我们添加到trafficScript下面的规则中,该规则将硬编码的html文件名上传到其他路径。现在,当我尝试访问我的网站时,它会显示维护页面,但不会显示维护页面中添加的图像。 但是,如果我不对.html文件名进行硬编码,但使用http.getPath(),然后从中获取文件名并用于导航(在脚本中注释),图像也可以正常显示。

如果有任何人可以请指出我在哪里有任何问题或有更好的方法来做到这一点。

  <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Sorry</title>
</head>
<body>
    <img src="/.extra/test.png">
    <h1>Our apologies</h1>
    We're sorry.  All of our operators are busy.  Please try again later.  
</body>
</html>

TrafficScript

#$url = http.getPath(); 
#if( ! string.regexmatch( $url, "^/\\.extra/(.*)$" ) ) {  
#   break;  
#} else {  
#   $file = $1;  
#}

$file = "App_Offline.html";
# If the file does not exist, stop  
if( ! resource.exists( $file ) ) break;  

# Serve the file from the conf/extra directory  
$contents = resource.get( $file );  
http.sendResponse( "200 OK", "text/html", $contents, "" ); 

1 个答案:

答案 0 :(得分:0)

我现在能够在html页面上显示图像,并在启用规则时将所有流量导航到此页面。我修改了下面的trafficscript

$url = http.getPath();  
if( ! string.regexmatch( $url, "^/\\.extra/(.*)$" ) ) {    
  http.setPath("/.extra/App_Offline.html");  
}  

$url = http.getPath();  

if( ! string.regexmatch( $url, "^/\\.extra/(.*)$" ) ) {    
  break;    
} else {    
  $file = $1;    
}  

# If the file does not exist, stop    
if( ! resource.exists( $file ) ) break;    

$mimes = [    
        "html"  => "text/html",    
        "jpg"    => "image/jpeg",    
        "jpeg"  => "image/jpeg",    
        "png"    => "image/png",    
        "gif"    => "image/gif",    
        "js"    => "application/x-javascript",    
        "css"    => "text/css"  ,    
        "ico"    => "image/x-icon" ,    
        "txt"    => "text/plain"    
        ];    
        if( string.regexmatch( $file , ".*\\.([^.]+)$" ) ) {    
            $mime = $mimes[ $1 ];    
        }    
        if( ! $mime ) $mime = "text/html";   

# Serve the file from the conf/extra directory    
$contents = resource.get( $file );    
http.sendResponse( "200 OK", $mime , $contents, "" );