2017-06-01 159 views
0

我正在嘗試AJAX-ify我的報告,以便繞過CloudFlare對通過其站點運行的請求施加的100秒超時。繞過CloudFlare的超時100秒

Is it possible to increase CloudFlare time-out?

我做了以下內容:

function ajaxReport() { 
    var seconds = prompt("Please enter how many seconds you want the report to run", "5"); 
    $('#imgWaiting').show(); 
    $.post("post/post_ajaxReport.jsp", 
    { 
    theParam:seconds 
    },function(data) { 
    $('#imgWaiting').hide(); 
    window.location=data; 
}); 

} 

和post_ajaxReport.jsp

<% 
int theParam=myFunctionToConvertStringToInt(request.getParameter("theParam")); 
int a=theParam/60; 
int b=theParam-a*60; 
String query="WAITFOR DELAY '00:"+a+":"+b+"';"; 
double d=myCustomCodeToRunQuery(query); 
String fileName=createReport(); 
%> 
<%=fileName%> 

的代碼在100秒偉大的工作如下。但沒有超過100秒的工作。

任何想法?

更新後反饋

我的報告現在正常工作而不AJAX(雖然有100秒超時與CloudFlare的)。我試圖將它們轉換爲AJAX,以避免灰色陰影子域,因爲我不想公開我的IP地址。如果我要灰化一個子域,我會在原始代碼上做這件事,這比AJAX簡單得多 - 如果我的代碼變了!我的問題是「如何修復我的AJAX代碼,這樣我就可以避免100秒的超時,但沒有暴露我的IP地址的缺點......」

回答

0

如果其他人有同樣的問題,我發佈我如何終於得到這個工作。我放棄了試圖使用AJAX來運行報表,但是通過一個線程運行報表,但使用AJAX來「輪詢」以檢查報表是否已經創建。我所做的基本如下。

請注意,我剝離了很多代碼,例如,安全例程和錯誤檢查例程,只是爲了給出基本框架。

我創建了一個名爲ThreadMyReport

public class ThreadMyReport implements Runnable { 

    String fileID = ""; 
    Date dateOfReport = null; 

    public ThreadMyReport(Date dateOfReport) { 
     this.fileID= "MyReport_" + UUID.randomUUID(); 
     this.dateOfReport = dateOfReport; 
    } 

    public void run() { 
     int a = ReportMyReport.loadAndSaveMyReport(dateOfReport, fileID); 
    } 


    public String getFileID() { 
     return fileID; 
    } 
} 

我所有的原代碼來生成報告ReportMyReport.loadAndSaveMyReport找到一個Java類。報告完成後,它會在服務器上保存一個帶有fileName fileID的文件。

我便開始一個線程去運行報告

ThreadMyReport a = new ThreadMyReport(theDate); 
    Thread theThread=new Thread(a); 
    theThread.start(); 
    fileID=a.getFileID(); 

我加入的JavaScript例程通過AJAX每秒該文件是否已經建立了檢查,如果已經創造了它,然後顯示報告。

<SCRIPT language="javascript"> 


    var myVar; 
    myVar=setInterval(function(){ 
    $.post("post/post_checkReportReady_xml.jsp", { 
     generatedReport: '<%=fileID%>' 
    }, function(data) { 
     if (data.indexOf("produced")>-1) { 
      clearInterval(myVar); 
      //display report 
     } 
     if (data.indexOf("failed")>-1) { 
      clearInterval(myVar); 
     } 
    }); 

}, 1000); 
     </SCRIPT> 

Ajax代碼看起來是這樣的:

 <% 
    String result=""; 

    String generatedReport=(request.getParameter("generatedReport")); 

    if(!"".equals(generatedReport)) { 
     String fileName2="My directory/"+generatedReport+".xlsm"; 
     java.io.File f = new java.io.File(fileName2); 
     if(f.exists()) { 
      result="produced"; 
     } 
    } 
} 

%> 
<%=result%> 
0

由於cloudflare不緩存html或xhr,你可以greycloud一個子域,但在服務器上使用它作爲別名。例如...

在CloudFlare的DNS:

  • WWW 123.123.123.123 =橙(保護)(僅DNS)
  • AJAX 123.123.123.123 =灰色

在你的網站控制面板添加ajax.mydomain.com作爲別名。

最後,在您的代碼中,使用繞過cloudflare命中您的服務器的fqdn。

function ajaxReport() { 
    var seconds = prompt("Please enter how many seconds you want the report to run", "5"); 
    $('#imgWaiting').show(); 
    $.post("//ajax.mydomain.com/post/post_ajaxReport.jsp", 
    { 
    theParam:seconds 
    },function(data) { 
    $('#imgWaiting').hide(); 
    window.location=data; 
}); 
} 

這會暴露您的IP地址。但是,根據返回的內容,應該沒有什麼性能損失。

+0

謝謝@jules的答覆。現在我的報告沒有AJAX就能正常工作(儘管CloudFlare有100秒的超時時間)。我試圖將它們轉換爲AJAX,以避免灰色陰影子域,因爲我不想公開我的IP地址。如果我要灰化一個子域,我會在原始代碼上做這件事,這比AJAX簡單得多 - 如果我的代碼變了!我的問題是如何解決我的AJAX代碼,以便我可以避免100秒的超時,但沒有暴露我的IP地址的缺點......也許這是不能做到的! – gordon613