aboutsummaryrefslogtreecommitdiff
path: root/src/client/Network.ts
diff options
context:
space:
mode:
authorNathan-SR <144961007+Nathan-SR@users.noreply.github.com>2025-03-04 04:32:50 -0500
committerNathan-SR <144961007+Nathan-SR@users.noreply.github.com>2025-03-04 04:32:50 -0500
commit95abdada5a275fc258fa72781f7f3c40c0b306ea (patch)
tree6d729cebe0937ae81108005de9895b5398d1f475 /src/client/Network.ts
parent0a8f3739cf5c30852f18751a4c05d81e0dabe928 (diff)
parent215ad40efa2e343e290d18bffbc55884829f1a0d (diff)
Merge branch 'master' of https://github.com/brown-dash/Dash-Web into Merge
Diffstat (limited to 'src/client/Network.ts')
-rw-r--r--src/client/Network.ts19
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 }));
+ });
}
/**