diff --git a/common/index.tsx b/common/index.tsx index 2fd71b8..5b4563e 100644 --- a/common/index.tsx +++ b/common/index.tsx @@ -3,10 +3,14 @@ export const get = async (url: string) => { const json = await resp.json(); return json; }; -export const post = async (url: string, json: any) => { +export const post = async ( + url: string, + json: any, + headers: Record = {} +) => { const resp = await fetch(url, { method: "POST", - headers: { "Content-Type": "application/json" }, + headers: { "Content-Type": "application/json", ...headers }, body: JSON.stringify(json), }); const result = await resp.json(); diff --git a/pages/edit.tsx b/pages/edit.tsx index c8db006..d48a538 100644 --- a/pages/edit.tsx +++ b/pages/edit.tsx @@ -2,10 +2,11 @@ import React from "react"; import { get, post } from "@/common"; const EditPage = () => { + const [token, setToken] = React.useState(""); const ref = React.useRef(); const upload = async () => { const html = ref.current.innerHTML; - await post("/api/html", { html }); + await post("/api/html", { html }, { token }); alert("Upload success"); refresh(); }; @@ -18,6 +19,11 @@ const EditPage = () => { }, []); return ( <> + setToken(event.target.value)} + />