public static async Task OnHttpRequest(Microsoft.AspNetCore.Http.HttpContext e) { try { if (e.Request.Path == "/v1") { await AcceptV1Request(e); } else if (e.Request.Path == "/") { await AcceptRootRequest(e); } else { e.Response.StatusCode = 404; await WriteStringToStreamAsync(e.Response.Body, "Not Found"); } } catch (Exception ex) { //Log and display error var error = await conn.LogHttpError(ex, new System.Collections.Generic.Dictionary <string, string>()); e.Response.StatusCode = 500; await WriteStringToStreamAsync(e.Response.Body, JsonConvert.SerializeObject(error, Newtonsoft.Json.Formatting.Indented)); } }
public static async Task OnHttpRequest(Microsoft.AspNetCore.Http.HttpContext e) { try { //Add headers e.Response.Headers.Add("Server", "Delta Web Map User Content"); e.Response.Headers.Add("Access-Control-Allow-Headers", "Authorization, Content-Type, Content-Length"); e.Response.Headers.Add("Access-Control-Allow-Origin", "https://deltamap.net"); e.Response.Headers.Add("Access-Control-Allow-Methods", "GET, POST, OPTIONS, DELETE, PUT, PATCH"); //If this is options, do cors if (e.Request.Method.ToUpper() == "OPTIONS") { await WriteStringToStreamAsync(e.Response.Body, "CORS OK"); return; } //Commit if (e.Request.Path == "/upload") { await Services.UploadService.OnHttpRequest(e); } else if (e.Request.Path.ToString().StartsWith("/u/")) { await Services.FileService.OnHttpRequest(e); } else { e.Response.StatusCode = 404; await WriteStringToStreamAsync(e.Response.Body, "Not Found"); } } catch (Exception ex) { //Log and display error var error = await conn.LogHttpError(ex, new System.Collections.Generic.Dictionary <string, string>()); e.Response.StatusCode = 500; await WriteStringToStreamAsync(e.Response.Body, JsonConvert.SerializeObject(error, Newtonsoft.Json.Formatting.Indented)); } }