refactor(ProxyController): Aktualisiert, um JsonResult zu verwenden, wenn es einen Körper in der Redir-Methode gibt.

This commit is contained in:
Developer 02 2025-01-30 11:39:18 +01:00
parent 1fde6e7e34
commit 7189b39d6b
3 changed files with 17 additions and 8 deletions

View File

@ -1,10 +1,7 @@
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
namespace DigitalData.Swagger.MockAPI.Controllers namespace DigitalData.Swagger.MockAPI.Controllers
{ {
[Route("api/[controller]")]
[ApiController] [ApiController]
public class MockController : ControllerBase public class MockController : ControllerBase
{ {

View File

@ -19,8 +19,7 @@ public class ProxyController(IOptions<OriginServerParams> originServerParamsOpti
var res = await origin.Url var res = await origin.Url
.AppendPathSegment(servicetierName) .AppendPathSegment(servicetierName)
.AppendPathSegment("ODataV4") .AppendPathSegment("ODataV4")
.AppendPathSegment(webserviceName) .AppendPathSegment(webserviceName + "_CreateInvoice")
.AppendPathSegment("_CreateInvoice")
.SetQueryParams(new { company }) .SetQueryParams(new { company })
//.WithOAuthBearerToken("my_oauth_token") //.WithOAuthBearerToken("my_oauth_token")
.PostAsync(); .PostAsync();
@ -33,6 +32,13 @@ public class ProxyController(IOptions<OriginServerParams> originServerParamsOpti
foreach (var (Name, Value) in res.Cookies.ToKeyValuePairs()) foreach (var (Name, Value) in res.Cookies.ToKeyValuePairs())
HttpContext.Response.Cookies.Append(Name, Value.ToString() ?? string.Empty); HttpContext.Response.Cookies.Append(Name, Value.ToString() ?? string.Empty);
return StatusCode(res.StatusCode, res); var body = res.GetJsonAsync<dynamic>();
if (body is not null)
return new JsonResult(body)
{
StatusCode = res.StatusCode
};
return StatusCode(res.StatusCode);
} }
} }

View File

@ -5,5 +5,11 @@
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning"
} }
}, },
"AllowedHosts": "*" "AllowedHosts": "*",
"OriginServer": {
"Url": "https://localhost:7248",
"Headers": {
}
}
} }