I am trying to resolve two errors on my kestrel middleware which is designed to handle a fetch request and return some JSON. (I am not interested in using MVC)
The code works, but I would like to remove these two errors:
In chrome I get this error:
net::ERR_INCOMPLETE_CHUNKED_ENCODING 200 (OK)
In kestrel I get this error:
"statuscode cannot be set because the response has already started"
public void Configure(
IApplicationBuilder app,
IHostingEnvironment env,
ILoggerFactory loggerFactory)
{
// some startup stuff...
app.Use(async (context, next) =>
{
if (context.Request.Path.HasValue && context.Request.Path.Value.Contains("searchjsfetch/"))
{
await context.Response.WriteAsync(JsonConvert.SerializeObject(simpleObject), Encoding.UTF8);
}
})
}
In typescript I fetch like this:
fetch(`${hostDomain}searchjsfetch/${email}/2/3`)
.then((response) => {
response.body.getReader().read().then((c) => {
return new TextDecoder("utf-8").decode(c.value);
});
})