簡體   English   中英

Angular和URL重寫捕獲反向代理調用

[英]Angular and URL rewrite capturing reverse proxy call

我在Angular.js應用程序中使用Accusoft的文檔查看器。 獲得其服務的唯一方法是在我的目錄之一上使用反向代理設置。 因此,我設置了“ pas-service”,其中包含一個web.config,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://localhost:3000/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

問題在於,要使angular正常工作,網站的重定向規則必須先捕獲該重定向規則,然后它才能返回調用並發送回index.html頁面。

這是網站主要部分的重寫規則中的內容:

<rewrite>
      <rules>
        <rule name="RemovevesSeldetailsscripts" stopProcessing="true">
          <match url="^(.*[/])scripts/(.*)$" />
          <conditions>
          </conditions>
          <action type="Redirect" url="scripts/{R:2}" />
        </rule>
        <rule name="Removevesseldetailscontent" stopProcessing="true">
          <match url="^(.*[/])assets/(.*)$" />
          <conditions>
          </conditions>
          <action type="Redirect" url="assets/{R:2}" />
        </rule>
        <rule name="Main Rule" enabled="true" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
                        <add input="{REQUEST_URI}" pattern="^/(pas-service)" negate="true" />
          </conditions>
          <action type="Rewrite" url="/jbv/index.html" />
        </rule>
      </rules>
    </rewrite>

如何使網站的主要重寫規則忽略此反向代理請求? 發生的情況是請求是以下URL:

http://localhost/jbv/pas-service/Page/q/0?DocumentID=uZcjEtW-7NshOyh8iEIFCx-EbvHyIAuha6D7tbQvV77O_FKs_P-3KN7rB9McjnnisxhPFv1Wy0f7K4t_Hc0Cc6A&Scale=1&ContentType=svga

它只是重定向到index.html頁面,而不是將調用結果返回給服務。 有任何想法嗎?

您是否嘗試過僅使用一組重寫規則? 無需使用兩個單獨的規則文件,只需將以下內容添加到您的主文件中:

<rule name="PasRewriteRule" stopProcessing="true">
  <match url="^(.*[/])pas-service/(.*)$" />
  <conditions>
  </conditions>
  <action type="Rewrite" url="http://localhost:3000/{R:2}" />
</rule>

在其他規則之前,將其添加到頂部,以確保首先匹配它。 然后,您可以刪除Accusoft pas-service文件夾。 請注意,由於我不確定您的應用程序的確切設置,您可能需要調整正則表達式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM