diff options
author | bobzel <zzzman@gmail.com> | 2025-03-16 19:02:56 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2025-03-16 19:02:56 -0400 |
commit | df708c90d8356934d2e3d9123129c761d328c1fe (patch) | |
tree | 98b0588710ac8ca00c303960da0851614aacf597 /src/client/Network.ts | |
parent | 7d9fae09e8906e5636f6ea695ad560797b08d023 (diff) | |
parent | f4042257be7359734a0dd35cedbf03fe4aa14cf1 (diff) |
Merge branch 'DocCreatorMenu-work' of https://github.com/brown-dash/Dash-Web into DocCreatorMenu-work
Diffstat (limited to 'src/client/Network.ts')
-rw-r--r-- | src/client/Network.ts | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/client/Network.ts b/src/client/Network.ts index 9afdc844f..a2ecf1bea 100644 --- a/src/client/Network.ts +++ b/src/client/Network.ts @@ -1,5 +1,4 @@ import formidable from 'formidable'; -import * as requestPromise from 'request-promise'; import { ClientUtils } from '../ClientUtils'; import { Utils } from '../Utils'; import { Upload } from '../server/SharedMediaTypes'; @@ -15,14 +14,18 @@ export namespace Networking { return (await fetch(relativeRoute)).text(); } - export async function PostToServer(relativeRoute: string, body?: unknown) { - const options = { - uri: ClientUtils.prepend(relativeRoute), + export function PostToServer(relativeRoute: string, body?: unknown) { + return fetch(ClientUtils.prepend(relativeRoute), { method: 'POST', - body, - json: true, - }; - return requestPromise.post(options); + headers: { + 'Content-Type': 'application/json', + }, + body: body ? JSON.stringify(body) : undefined, + }).then(async response => { + if (response.ok) return response.json() as object; + + return await response.text().then(text => ({ error: '' + response.status + ':' + response.statusText + '-' + text })); + }); } /** |