diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-07-08 02:16:42 +1000 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-07-08 02:23:23 +1000 |
| commit | 2508c7cf38ed412bdffffd74b31d003651571187 (patch) | |
| tree | ab27930fc6fc9542710e1391332c3e1c2d6d7737 /src/lib.ts | |
| parent | ef4a9b9223d6019f0b782eb2f944f3cfe2b6ed41 (diff) | |
Add basic conversion to POST requeststest-post-reqs
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.
Diffstat (limited to 'src/lib.ts')
| -rw-r--r-- | src/lib.ts | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -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}`); |
