-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace EoaServer.Proxy; | ||
|
||
public interface IProxyService | ||
{ | ||
Task<object> ProxyGetRequestAsync(string targetUrl); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace EoaServer.Options; | ||
|
||
public class DidServerOptions | ||
{ | ||
public string BaseUrl { get; set; } | ||
public int Timeout { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> didServerOptions, IHttpClientFactory httpClientFactory) | ||
{ | ||
_didServerOptions = didServerOptions.Value; | ||
_httpClient = httpClientFactory.CreateClient(); | ||
} | ||
|
||
public async Task<object> 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<object?>(responseBody); | ||
return new JsonResult(result) | ||
{ | ||
ContentType = "application/json" | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<object> ProxyAsync(string proxyUrl) | ||
{ | ||
return await _proxyService.ProxyGetRequestAsync(proxyUrl); | ||
} | ||
} |