cancel
Showing results for 
Search instead for 
Did you mean: 

Stingray steelapp, displaying a image on a maintenance page

SOLVED
Highlighted
New Contributor

Stingray steelapp, displaying a image on a maintenance page

Hi All,

We have setup our application on stingray, one of the requirement was for us to display a maintenance page when the administrator wants to update the system.

So for this we created a html page with a logo image and uploaded both the .html and .png image to the Extra File/ miscellaneous path. We created a rule, in the rule we added below trafficScript that has the hardcoded html file name that is uploaded to the miscellaneous path. And now with this when I try to access my website it displays the maintenance page, but the image added in the maintenance page is not displayed. But if I don't hardcode the .html file name but use the http.getPath() and then from that get the file name and use for navigation(commented in the script), image is also displayed fine when we browse to /.extra/App_Offline.html.

If anyone can please point me where if there is any problem or if there is a better way to do this.

  <!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. We will be back shortly. 

</body>
  </html>

The 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, "" );

Thanks

Arvind

6 REPLIES
Contributor

Re: Stingray steelapp, displaying a image on a maintenance page

your problem is the mimetype, your image will be send as "text/html", which is wrong.

copied from somewhere here:


if (resource.exists($filename)) {


         $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( $filename, ".*\\.([^.]+)$" ) ) {


            $mime = $mimes[ $1 ];


         }


         if( ! $mime ) $mime = "text/plain";


         #


         # Serve the file from the conf/extra directory


         $contents = resource.get( $filename );


         $header = "Content-Length: ".string.len($contents)."\r\n".


                   "Expires: ".sys.gmtime.format( "%a, %d %b %Y %T GMT", sys.time()+604800 )."\r\n".


                   "Cache-Control: max-age=604800\r\n".


                   "";


          http.sendResponse( "200 OK", $mime, $contents, $header );


         #


      }


Best Regards,

Jochen

New Contributor

Re: Stingray steelapp, displaying a image on a maintenance page

Hi Jochen,

Thank you for the reply. I had tried with the mime selection code as mentioned by you before, but that did not help, since i am using a .html page mime was always "text/plan" hence had removed it and hard coded the value.

Even with my original code, what i am not able to get is, why is the image displayed in the html page when in the IE address when i browse to the path https://<mywebsite>/.extra/App_Offline.html and used the http.getPath() to get the url.

But when i hardcode the same url in the script, the html page is displayed but without the image.

I even tried http.setPath("/.extra/App_Offline.html"); to replace the URL with my error page and then used http.getPath()  just to try but still dint get the image.

Thanks

Arvind

Contributor

Re: Stingray steelapp, displaying a image on a maintenance page

do you see 2 requests from clients?

first one for the html file

second one for the image

is this correct?

btw: here is the document explaining in detail Sending custom error pages

New Contributor

Re: Stingray steelapp, displaying a image on a maintenance page

Hi Jochen,

There is only one request that is received for the html page and this is handled and the page is displayed. I dint see a separate request from client for the image. The images are displayed along with the html page when navigated using the URL, but when navigating from the script, the image path is still same but it is not rendered. I had used the document as a reference to create my setup, the document explains the use of error_file setting to show a maintenance page when all servers are down, i tried similarly to display the maintenance page when the user requires to show this page even if the server is alive, by enabling the rule.

Thanks

Arvind

Contributor

Re: Stingray steelapp, displaying a image on a maintenance page

Hi Arvind,

as far as i understand the system, you can't serve directly content from the extras-directory. So, creating just a link in your html file to the extra-directory will not work (you can't open the image via this url).

Thats the reason, why in the example, all content ist delivered via resource.get and http.response trafficscript.

I just used the original example trafficscript and it works perfectly with your html-file (including the image).

-Jochen

New Contributor

Re: Re: Stingray steelapp, displaying a image on a maintenance page

Hi Jochen,

Thank you very much, i am now able to display the image on the html page and navigate all the traffic to this page when the rule is enabled. I modified the trafficscript from the example as below.


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


Thanks

Arvind