public async void render(string viewPath, object data) { try { var html = ServerHelpers.GetFileTemplate(viewPath, data); send(html, 200, "text/html"); } catch (Exception ex) { if (JintAddons.debug) { Log.Error(ex.Message + " " + ex.StackTrace); } send(StaticTemplates.OopsTemplate(ex), 500, "text/html"); } }
public async void redirect(string route) { try { context.Response.RedirectLocation = route; context.Response.Redirect(route); } catch (Exception ex) { if (JintAddons.debug) { Log.Error(ex.Message + " " + ex.StackTrace); } send(StaticTemplates.OopsTemplate(ex), 500, "text/html"); } }
public async void send(string data, int statusCode, string contentType) { try { var response = context.Response; byte[] bytes = Encoding.UTF8.GetBytes(data); response.ContentType = contentType; response.ContentEncoding = Encoding.UTF8; response.ContentLength64 = bytes.LongLength; response.StatusCode = statusCode; await response.OutputStream.WriteAsync(bytes, 0, bytes.Length); response.Close(); } catch (Exception ex) { if (JintAddons.debug) { Log.Error(ex.Message + " " + ex.StackTrace); } send(StaticTemplates.OopsTemplate(ex), 500, "text/html"); } }