diff --git a/src/EoaServer.Application.Contracts/Proxy/IProxyService.cs b/src/EoaServer.Application.Contracts/Proxy/IProxyService.cs new file mode 100644 index 0000000..c41c4b1 --- /dev/null +++ b/src/EoaServer.Application.Contracts/Proxy/IProxyService.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; + +namespace EoaServer.Proxy; + +public interface IProxyService +{ + Task ProxyGetRequestAsync(string targetUrl); +} \ No newline at end of file diff --git a/src/EoaServer.Application/EoaServerApplicationModule.cs b/src/EoaServer.Application/EoaServerApplicationModule.cs index 307b1ca..ede4a4c 100644 --- a/src/EoaServer.Application/EoaServerApplicationModule.cs +++ b/src/EoaServer.Application/EoaServerApplicationModule.cs @@ -42,6 +42,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) Configure(configuration.GetSection("TokenSpender")); Configure(configuration.GetSection("ActivityOptions")); Configure(configuration.GetSection("AElfScanOptions")); + Configure(configuration.GetSection("DidServerOptions")); Configure(configuration.GetSection("Tokens")); Configure(configuration.GetSection("TokenInfo")); Configure(configuration.GetSection("AssetsInfo")); diff --git a/src/EoaServer.Application/Options/DidServerOptions.cs b/src/EoaServer.Application/Options/DidServerOptions.cs new file mode 100644 index 0000000..a60a6ce --- /dev/null +++ b/src/EoaServer.Application/Options/DidServerOptions.cs @@ -0,0 +1,7 @@ +namespace EoaServer.Options; + +public class DidServerOptions +{ + public string BaseUrl { get; set; } + public int Timeout { get; set; } +} \ No newline at end of file diff --git a/src/EoaServer.Application/Proxy/ProxyService.cs b/src/EoaServer.Application/Proxy/ProxyService.cs new file mode 100644 index 0000000..a786a5c --- /dev/null +++ b/src/EoaServer.Application/Proxy/ProxyService.cs @@ -0,0 +1,42 @@ +using System; +using System.Net.Http; +using System.Threading.Tasks; +using EoaServer.Options; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; +using Volo.Abp; +using Volo.Abp.Auditing; +using JsonSerializer = System.Text.Json.JsonSerializer; + +namespace EoaServer.Proxy; + +[RemoteService(false)] +[DisableAuditing] +public class ProxyService : EoaServerBaseService, IProxyService +{ + private readonly DidServerOptions _didServerOptions; + private readonly HttpClient _httpClient; + + public ProxyService(IOptionsSnapshot didServerOptions, IHttpClientFactory httpClientFactory) + { + _didServerOptions = didServerOptions.Value; + _httpClient = httpClientFactory.CreateClient(); + } + + public async Task ProxyGetRequestAsync(string targetUrl) + { + var targetRequest = new HttpRequestMessage + { + Method = HttpMethod.Get, + RequestUri = new Uri(_didServerOptions.BaseUrl + "/" + targetUrl), + }; + + var response = await _httpClient.SendAsync(targetRequest, HttpCompletionOption.ResponseHeadersRead); + var responseBody = await response.Content.ReadAsStringAsync(); + var result = JsonSerializer.Deserialize(responseBody); + return new JsonResult(result) + { + ContentType = "application/json" + }; + } +} \ No newline at end of file diff --git a/src/EoaServer.HttpApi.Host/appsettings.json b/src/EoaServer.HttpApi.Host/appsettings.json index 45ca644..31aebd6 100755 --- a/src/EoaServer.HttpApi.Host/appsettings.json +++ b/src/EoaServer.HttpApi.Host/appsettings.json @@ -95,6 +95,10 @@ "BaseUrl": "https://testnet.aelfscan.io", "Timeout": 5000 }, + "DidServerOptions": { + "BaseUrl": "https://aa-portkey-test.portkey.finance", + "Timeout": 5000 + }, "ActivityOptions": { "ActivityTransactionFeeFix": [ { diff --git a/src/EoaServer.HttpApi/Controllers/ProxyController.cs b/src/EoaServer.HttpApi/Controllers/ProxyController.cs new file mode 100644 index 0000000..8e017ac --- /dev/null +++ b/src/EoaServer.HttpApi/Controllers/ProxyController.cs @@ -0,0 +1,28 @@ +using System.Threading.Tasks; +using Asp.Versioning; +using EoaServer.Proxy; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp; + +namespace EoaServer.Controllers; + +[RemoteService] +[Area("proxy")] +[ControllerName("Proxy")] +[Route("proxy")] +public class ProxyController : EoaServerBaseController +{ + private readonly IProxyService _proxyService; + + public ProxyController(IProxyService proxyService) + { + _proxyService = proxyService; + } + + [HttpGet] + [Route("{**proxyUrl}")] + public async Task ProxyAsync(string proxyUrl) + { + return await _proxyService.ProxyGetRequestAsync(proxyUrl); + } +} \ No newline at end of file