diff --git a/public/configuration.json b/public/configuration.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/public/configuration.json @@ -0,0 +1 @@ +{} diff --git a/src/App.jsx b/src/App.jsx index 1187049..6da0b20 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -9,6 +9,7 @@ function Editor({ endpoint, queries, prefix }) { const [yasgui, setYasgui] = useState(); const [counter, setCounter] = useState(0); const ref = useRef(null); + const editorRef = useRef(null); const [inserted, setInserted] = useState(false); @@ -33,10 +34,15 @@ function Editor({ endpoint, queries, prefix }) { }; useLayoutEffect(() => { + if (editorRef.current.getAttribute("data-yasgui") === "true") { + return; + } + localStorage.removeItem("yagui__config"); + editorRef.current.setAttribute("data-yasgui", "true"); setYasgui( // eslint-disable-next-line no-undef - new Yasgui(document.getElementById("editor"), { + new Yasgui(editorRef.current, { requestConfig: { endpoint } @@ -48,7 +54,7 @@ function Editor({ endpoint, queries, prefix }) { <>
{queries.map((query, i) => ( - @@ -56,6 +62,7 @@ function Editor({ endpoint, queries, prefix }) {
{ if ( endpoint !== defaultEndpoint && diff --git a/vite.config.ts b/vite.config.ts index 8bf7811..eedcc76 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,6 +1,8 @@ -import { defineConfig } from 'vite' -import react from '@vitejs/plugin-react-swc' +import { defineConfig } from "vite"; +import react from "@vitejs/plugin-react-swc"; import { configDefaults } from "vitest/config"; +import { readFileSync } from "fs"; +import { resolve } from "path"; // https://vitejs.dev/config/ export default defineConfig({ @@ -19,6 +21,30 @@ export default defineConfig({ outDir: "temp_dist" }, server: { - port: 3000 + port: 3000, + proxy: { + "/queries/queries.json": { + bypass: function (req, res) { + res.setHeader("Content-Type", "application/json"); + res.end( + readFileSync( + resolve(import.meta.dirname, "pages/queries/queries.json") + ).toString() + ); + return false; + } + }, + "^/queries/.*.txt": { + bypass: function (req, res) { + res.setHeader("Content-Type", "application/json"); + res.end( + readFileSync( + resolve(import.meta.dirname, "pages/", req.url!.replace("/", "")) + ).toString() + ); + return false; + } + } + } } });