我对API网关还很陌生,有一个理解上的问题。我想把一系列(微)服务放在一个端点后面。
为此,我建立了一个ASP.NET Core应用程序,并添加了ThreeMammals Ocelot包。 通过文档的帮助,我配置了上游和下游。 到目前为止,一切都很好。
客户端向http://mygateway:4242/s1/{api}发出请求,并从Service1获取JSON或XML响应,就像预期的那样。
对于http://mygateway:4242/s2/{api}也是同样的情况,得到了预期的结果!
我的理解问题出现在Service3上。 当我发送请求到http://mygateway/s3/时,我得到了index.html作为响应。
index.html本身通过link标签要求加载CSS文件'xyz.css'并强制客户端加载该文件。
<head>
<link rel="stylesheet" type="text/css" href="xyz.css">
</head>
客户端发送给“mygateway”的请求URL是http://mygateway:4242/xyz.css,而不是http://mygateway:4242/s3/xyz.css,因此响应是404未找到,因为“mygateway”对“xyz.css”一无所知。
我该如何解决这个路由问题?
是否可以使用ocelot中间件解决此问题?还是我需要为SinglePageApplication(SPA)的服务(Service3)使用其他东西?
也许将SPA放在网关后面根本不可能或不正确。我希望您能给我一些提示,以便在网关后面访问SPA或MVC网站。
谢谢iBot
更新: 附上index.html的代码。我认为这很简单明了。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title</title>
<base href="/" />
<link rel="stylesheet" type="text/css" href="dist/xyz.css">
</head>
<body>
<div id="appContainer"></div>
<script src="dist/xyz.js" asp-append-version="true"></script>
</body>
</html>
index.html
的代码吗? - Chetan