我试图在同一个Azure Web应用上为我的Angular SPA和运行Spring-boot后端API提供服务,以便它们共享同一个域。
我已经创建了一个虚拟目录 api/
用于运行我的后台,并将根虚拟目录指向angular文件。
我使用了默认的 web.config
在每个文件夹中。在后台 wwwroot/api
:
<configuration>
<system.webServer>
<handlers>
<add name="MyhttpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
</handlers>
<httpPlatform processPath="%JAVA_HOME%\bin\java.exe"
arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar "D:\home\site\wwwroot\api\my_packaged_api-1.0-SNAPSHOT.jar" ">
</httpPlatform>
</system.webServer>
</configuration>
而在angular app文件夹中 wwwroot/dist
:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Angular Routes" 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="^/assets/(.*)$" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
</configuration>
API工作正常,但当我试图从我的Angular应用程序中访问任何文件时,我得到一个来自Tomcat服务器的404。wwwroot/dist
. 所有的404最后都会出现在这个进程日志中。
检查请求诊断,我可以看到重写规则正确地工作并找到了我的文件。但似乎请求还是被传递给了这个额外的Tomcat进程,并返回404。
我应该在web.config中更改什么,以便它实际返回我的文件吗?
固定它与两个东西在根web.config中的 wwwroot/dist
:
inheritInChildApplications="false"
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<clear />
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
</handlers>
<rewrite>
...