From 6b39168be258d344b3ac458e64217afdd90aecc9 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 29 Jan 2022 22:55:44 -0800 Subject: [PATCH] Add react-env to try to get it to work --- package-lock.json | 11 +++++++++++ package.json | 5 ++++- utils/api.tsx | 10 +++------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index feca2021..700813f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "react": "17.0.2", "react-cookie": "^4.1.1", "react-dom": "^17.0.2", + "react-env": "^0.0.0", "react-i18next": "^11.15.3", "react-router-dom": "^6.2.1", "sass": "^1.49.0" @@ -5811,6 +5812,11 @@ "react": "17.0.2" } }, + "node_modules/react-env": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/react-env/-/react-env-0.0.0.tgz", + "integrity": "sha1-+p8K+Y1VWwsPYO3Mrg1juj67rVE=" + }, "node_modules/react-i18next": { "version": "11.15.3", "resolved": "https://registry.npmjs.org/react-i18next/-/react-i18next-11.15.3.tgz", @@ -10852,6 +10858,11 @@ "scheduler": "^0.20.2" } }, + "react-env": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/react-env/-/react-env-0.0.0.tgz", + "integrity": "sha1-+p8K+Y1VWwsPYO3Mrg1juj67rVE=" + }, "react-i18next": { "version": "11.15.3", "resolved": "https://registry.npmjs.org/react-i18next/-/react-i18next-11.15.3.tgz", diff --git a/package.json b/package.json index d61e8f5d..76bbfc92 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,9 @@ { "name": "grid-web", "private": true, - "cacheDirectories": [".next/cache"], + "cacheDirectories": [ + ".next/cache" + ], "scripts": { "dev": "next dev -p 1234", "build": "next build", @@ -22,6 +24,7 @@ "react": "17.0.2", "react-cookie": "^4.1.1", "react-dom": "^17.0.2", + "react-env": "^0.0.0", "react-i18next": "^11.15.3", "react-router-dom": "^6.2.1", "sass": "^1.49.0" diff --git a/utils/api.tsx b/utils/api.tsx index 90b897da..2ef81102 100644 --- a/utils/api.tsx +++ b/utils/api.tsx @@ -1,4 +1,5 @@ import axios, { AxiosRequestConfig, AxiosResponse } from "axios" +import { env } from 'react-env' interface Entity { name: string @@ -23,9 +24,6 @@ class Api { constructor({url}: {url: string}) { this.url = url this.endpoints = {} - - console.log(`api url ${process.env.REACT_APP_SIERO_API_URL}`) - console.log(`siero url ${process.env.REACT_APP_SIERO_OAUTH_URL}`) } createEntity(entity: Entity) { @@ -49,8 +47,7 @@ class Api { } login(object: {}) { - const oauthUrl = (process.env.REACT_APP_SIERO_OAUTH_URL) ? process.env.REACT_APP_SIERO_OAUTH_URL : 'http://127.0.0.1:3000/oauth' - return axios.post(`${ oauthUrl }/token`, object) + return axios.post(`${ env("REACT_APP_SIERO_OAUTH_URL") }/token`, object) } search(object: string, query: string, excludes: string) { @@ -69,8 +66,7 @@ class Api { } } -const apiUrl = (process.env.REACT_APP_SIERO_API_URL) ? process.env.REACT_APP_SIERO_API_URL : 'http://127.0.0.1:3000/api/v1' -const api: Api = new Api({ url: apiUrl }) +const api: Api = new Api({ url: env("REACT_APP_SIERO_API_URL") }) api.createEntity( { name: 'users' }) api.createEntity( { name: 'parties' }) api.createEntity( { name: 'characters' })