0

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

因此,为此我们创建了一个带有徽标图像的 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>

交通脚本

#$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, "" ); 
4

1 回答 1

0

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

$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, "" ); 
于 2014-07-03T06:04:11.083 回答