From 2508c7cf38ed412bdffffd74b31d003651571187 Mon Sep 17 00:00:00 2001 From: Terry Truong Date: Fri, 8 Jul 2022 02:16:42 +1000 Subject: Add basic conversion to POST requests Using fetch() sent a CORS preflight request, which python's basic server couldn't understand. Using fetch()'s 'no-cors' option seems to just fail. Ended up using Vite's proxy functionality again. CGI script also got unexpected empty command line argument. --- src/lib.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/lib.ts b/src/lib.ts index faec861..8aaeb47 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -7,15 +7,22 @@ import {LayoutOptions} from './layout'; import {getBreakpoint, Breakpoint, getScrollBarWidth, onTouchDevice} from './util'; // For server requests -const SERVER_URL = 'http://localhost:8000/cgi-bin/data.py' +const SERVER_URL = 'http://localhost:3000/cgi-bin/data.py' export async function queryServer(params: URLSearchParams){ // Construct URL let url = new URL(SERVER_URL); - url.search = params.toString(); + //url.search = params.toString(); // Query server let responseObj; try { - let response = await fetch(url.toString()); + let response = await fetch(url.toString(), { + method: 'POST', + headers: { + 'Content-type': 'application/json', + }, + body: JSON.stringify({params: params.toString()}), + }); + console.log(response) responseObj = await response.json(); } catch (error){ console.log(`Error with querying ${url}: ${error}`); -- cgit v1.2.3