summaryrefslogtreecommitdiff
path: root/public/src/api.tsx
diff options
context:
space:
mode:
authoraura <nw@moneybot.cc>2026-02-19 19:57:10 +0100
committeraura <nw@moneybot.cc>2026-02-19 19:57:10 +0100
commitbedf43af45d97a10a6f62b4f1bb21cd66fda1d71 (patch)
tree6501bb95977a574c188bef6a228ff7500b243f3a /public/src/api.tsx
parentb5fca421c8f5f0f8f26d1392ef48635196887fa3 (diff)
empty moneyjsx site
Diffstat (limited to 'public/src/api.tsx')
-rw-r--r--public/src/api.tsx39
1 files changed, 39 insertions, 0 deletions
diff --git a/public/src/api.tsx b/public/src/api.tsx
new file mode 100644
index 0000000..fa941ec
--- /dev/null
+++ b/public/src/api.tsx
@@ -0,0 +1,39 @@
+export const url = "https://forum.networkheaven.net/api/";
+
+export interface ReqParams {
+ method: string,
+ body?: string,
+}
+
+export async function post( endpoint: string, body: Object ) {
+ return await req( endpoint, {
+ method: "POST",
+ body: JSON.stringify( body ),
+ } );
+}
+
+export async function req( endpoint: string, params: ReqParams ) {
+ const res = await fetch( `${url}/${endpoint}`, {
+ method: params.method,
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: params.body,
+ } );
+
+ if( !res.ok ) {
+ let json = null;
+ try {
+ json = await res.json();
+ } catch( e: any ) {
+ throw new Error( "error contacting server" );
+ }
+
+ throw new Error( json.msg );
+ }
+
+ const json = await res.json();
+ if( json.status != 'ok' )
+ throw new Error( json.msg );
+ return json;
+}