-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
32 lines (23 loc) · 855 Bytes
/
Copy pathProgram.cs
File metadata and controls
32 lines (23 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCors(options => {
options.AddDefaultPolicy(builder => {
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
var app = builder.Build();
app.UseCors();
app.MapGet("/", () => Results.BadRequest("Only POST allowed"));
app.MapPost("/", async (HttpContext context) => {
using var buffer = new MemoryStream();
await context.Request.Body.CopyToAsync(buffer, 4096);
buffer.Position = 0;
var assm = new AssemblyBytes(buffer);
var options = context.RequestServices.GetService<IOptions<JsonOptions>>();
var json = assm.Node.ToJson(options?.Value.JsonSerializerOptions);
await context.Response.WriteAsync(json);
});
app.Run();