From 30685881112689e9be27834d1f9581d00eb9f066 Mon Sep 17 00:00:00 2001 From: Thomas Miceli <27960254+thomiceli@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:43:12 +0200 Subject: [PATCH] Send Markdown preview data as form params (#347) --- internal/web/server.go | 2 +- public/editor.ts | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/web/server.go b/internal/web/server.go index 4869b6e8..65abe0a3 100644 --- a/internal/web/server.go +++ b/internal/web/server.go @@ -251,7 +251,7 @@ func NewServer(isDev bool, sessionsPath string) *Server { g1.Use(csrfInit) g1.GET("/", create, logged) g1.POST("/", processCreate, logged) - g1.GET("/preview", preview, logged) + g1.POST("/preview", preview, logged) g1.GET("/healthcheck", healthcheck) g1.GET("/metrics", metrics) diff --git a/public/editor.ts b/public/editor.ts index f682418f..7a002cc4 100644 --- a/public/editor.ts +++ b/public/editor.ts @@ -71,11 +71,12 @@ document.addEventListener("DOMContentLoaded", () => { cmeditor!.classList.remove("hidden-important"); return; } else { - fetch(`${baseUrl}/preview?` + new URLSearchParams({ - content: editor.state.doc.toString() - }), { - method: 'GET', + const formData = new FormData(); + formData.append('content', editor.state.doc.toString()); + fetch(`${baseUrl}/preview`, { + method: 'POST', credentials: 'same-origin', + body: formData }).then(r => r.text()).then(r => { let divpreview = dom.querySelector("div.preview") as HTMLElement; divpreview!.innerHTML = r;