Add react-env to try to get it to work

This commit is contained in:
Justin Edmund 2022-01-29 22:55:44 -08:00
parent 9305a8bd20
commit 6b39168be2
3 changed files with 18 additions and 8 deletions

11
package-lock.json generated
View file

@ -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",

View file

@ -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"

View file

@ -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' })