make api domain more flexible

This commit is contained in:
Michael Fatemi 2021-07-15 07:39:30 -04:00
parent 3a761ffc8b
commit d276d02cc4

View File

@ -1,7 +1,18 @@
import { GroupPreview } from './GroupJoinerLink'; import { GroupPreview } from './GroupJoinerLink';
import { IInvitation, IEventSignup, ICarpool, IEvent, IGroup } from './types'; import { IInvitation, IEventSignup, ICarpool, IEvent, IGroup } from './types';
const base = process.env.REACT_APP_API_DOMAIN + 'api'; const base = (() => {
const domain =
process.env.NODE_ENV === 'production'
? process.env.REACT_APP_API_PROD
: process.env.REACT_APP_API_LOCAL;
if (domain?.endsWith('/')) {
return domain.slice(0, -1) + '/api';
} else {
return domain + '/api';
}
})();
async function post(path: string, data: any) { async function post(path: string, data: any) {
const res = await fetch(base + path, { const res = await fetch(base + path, {