Add .env.example to React app

This commit is contained in:
M. Mert Yildiran
2021-08-20 02:20:28 +03:00
parent fb56106741
commit d6446c9c02
4 changed files with 10 additions and 6 deletions

3
.gitignore vendored
View File

@@ -23,3 +23,6 @@ build
# Ignore the scripts that are created for development
*dev.*
# Environment variables
.env

View File

@@ -3,6 +3,7 @@ FROM node:14-slim AS site-build
WORKDIR /app/ui-build
COPY ui .
RUN rm .env
RUN npm i
RUN npm run build

2
ui/.env.example Normal file
View File

@@ -0,0 +1,2 @@
REACT_APP_OVERRIDE_WS_URL="ws://localhost:8899/ws"
REACT_APP_OVERRIDE_API_URL="http://localhost:8899/api/"

View File

@@ -2,17 +2,15 @@ import * as axios from "axios";
const mizuAPIPathPrefix = "/mizu";
// When working locally (with npm run start) change to:
// export const MizuWebsocketURL = `ws://localhost:8899${mizuAPIPathPrefix}/ws`;
export const MizuWebsocketURL = `ws://${window.location.host}${mizuAPIPathPrefix}/ws`;
// When working locally cp `cp .env.example .env`
export const MizuWebsocketURL = process.env.REACT_APP_OVERRIDE_WS_URL ? process.env.REACT_APP_OVERRIDE_WS_URL : `ws://${window.location.host}${mizuAPIPathPrefix}/ws`;
export default class Api {
constructor() {
// When working locally (with npm run start) change to:
// const apiURL = `http://localhost:8899/${mizuAPIPathPrefix}/api/`;
const apiURL = `${window.location.origin}${mizuAPIPathPrefix}/api/`;
// When working locally cp `cp .env.example .env`
const apiURL = process.env.REACT_APP_OVERRIDE_API_URL ? process.env.REACT_APP_OVERRIDE_API_URL : `${window.location.origin}${mizuAPIPathPrefix}/api/`;
this.client = axios.create({
baseURL: apiURL,