我的 ASP.NET Core 3 服务器模板项目工作正常,因此我可以在https://localhost:5000浏览它。我还有一个在端口 4000 上运行的同一个 localhost 上的节点服务器,当我在https://localhost:4000浏览到它时它工作正常。
我想要的是所有进入https://localhost:5000/nodejs的请求都转到https://localhost:4000/。例如,我想要
https://localhost:5000/api/Images/peter.png
返回通常从https://localhost:4000/Images/peter.png 提供的内容
(当然,所有其他请求都应该类似地映射。所有 url,而不仅仅是我上面提到的那个)。
我尝试使用 nuget 包 AspNetCore.Proxy,当我如下使用它时,它只代理根而不是任何其他 URL。
将所有 URL 从我的 asp.net 核心项目代理到我的节点服务器的最简单方法是什么?
ApiController.js
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using AspNetCore.Proxy;
namespace reactapp.Controllers
{
public class NextJsController : ControllerBase
{
[Route("nodejs")]
public Task OpenNextJs()
{
return this.ProxyAsync($"http://localhost:4000");
}
}
}
并且在startup.js
services.AddProxies();