From 14c4ded29e781dbf4f53344c19374ea4cb7ed4b6 Mon Sep 17 00:00:00 2001 From: Michael Fatemi Date: Thu, 8 Jul 2021 00:59:09 -0400 Subject: [PATCH] integrate digitalocean api --- .env | 3 ++- src/components/Authentication/createSession.ts | 6 +++++- src/components/api.ts | 8 +++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.env b/.env index 76f22a1..f4f9697 100644 --- a/.env +++ b/.env @@ -1 +1,2 @@ -REACT_APP_API_ENDPOINT=http://localhost:5000/api \ No newline at end of file +REACT_APP_API_ENDPOINT_0=http://localhost:5000/api +REACT_APP_API_DOMAIN=https://wheelshare-altbackend-2efyw.ondigitalocean.app/ diff --git a/src/components/Authentication/createSession.ts b/src/components/Authentication/createSession.ts index 7315d0e..40073ef 100644 --- a/src/components/Authentication/createSession.ts +++ b/src/components/Authentication/createSession.ts @@ -1,5 +1,9 @@ +const domain = process.env.REACT_APP_API_DOMAIN; + +console.log({ domain }); + export async function createSession(code: string, redirectUrl: string) { - const res = await fetch('http://localhost:5000/create_session', { + const res = await fetch(domain + 'create_session', { method: 'post', body: JSON.stringify({ code, redirectUrl }), headers: { diff --git a/src/components/api.ts b/src/components/api.ts index 86e93f1..98c8d86 100644 --- a/src/components/api.ts +++ b/src/components/api.ts @@ -2,8 +2,10 @@ import { IEventSignup } from './Event'; import { GroupPreview } from './GroupJoinerLink'; import { IInvitation } from './types'; +const base = process.env.REACT_APP_API_DOMAIN + 'api'; + async function post(path: string, data: any) { - const res = await fetch('http://localhost:5000/api' + path, { + const res = await fetch(base + path, { method: 'post', body: JSON.stringify(data), headers: { @@ -15,7 +17,7 @@ async function post(path: string, data: any) { } async function delete$(path: string) { - const res = await fetch('http://localhost:5000/api' + path, { + const res = await fetch(base + path, { method: 'delete', headers: { Authorization: 'Bearer ' + localStorage.getItem('session_token'), @@ -26,7 +28,7 @@ async function delete$(path: string) { } async function get(path: string) { - const res = await fetch('http://localhost:5000/api' + path, { + const res = await fetch(base + path, { headers: { Authorization: 'Bearer ' + localStorage.getItem('session_token'), },