feat(ProxyController): Umleitungsendpunkt für Post-Requests mit dem Muster „{ServicetierName}/ODataV4/{WebserviceName}_CreateInvoice“ implementiert

This commit is contained in:
Developer 02 2025-01-30 10:20:00 +01:00
parent 782680cda2
commit 54eca6fceb
2 changed files with 40 additions and 1 deletions

View File

@ -0,0 +1,38 @@
namespace DigitalData.Swagger.Proxy.Controllers;
using DigitalData.Swagger.Proxy.Configs;
using Flurl;
using Flurl.Http;
using Flurl.Util;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System.Threading.Tasks;
[ApiController]
public class ProxyController(IOptions<OriginServerParams> originServerParamsOptions) : ControllerBase
{
private readonly OriginServerParams origin = originServerParamsOptions.Value;
[HttpPost("{servicetierName}/ODataV4/{webserviceName}_CreateInvoice")]
public async Task<IActionResult> Redir([FromRoute] string servicetierName, [FromRoute] string webserviceName, [FromQuery] string company)
{
var res = await origin.Url
.AppendPathSegment(servicetierName)
.AppendPathSegment("ODataV4")
.AppendPathSegment(webserviceName)
.AppendPathSegment("_CreateInvoice")
.SetQueryParams(new { company })
//.WithOAuthBearerToken("my_oauth_token")
.PostAsync();
// set headers
foreach (var (Name, Value) in res.Headers)
HttpContext.Response.Headers[Name] = Value;
// set cookies
foreach (var (Name, Value) in res.Cookies.ToKeyValuePairs())
HttpContext.Response.Cookies.Append(Name, Value.ToString() ?? string.Empty);
return StatusCode(res.StatusCode, res);
}
}

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Flurl.Http" Version="4.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>