diff --git a/README.md b/README.md index a3a5baa8fd45b0326735dab10031481a9b6004e6..bd69a26054ee64499f8bbb209e3b407f505a0a89 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,6 @@ Run client and server concurrently: ## Deploy with Docker -Note: the Docker container is meant to run on a server (NODE_ENV=production). If you want -to run it on localhost, the API url needs to be changed in `src/client/epics/index.js`. - ### Build `docker build -t mmm-web-app-c .` diff --git a/src/client/configs/config.js b/src/client/configs/config.js index 81e667dd906b72664dc4fc3e31a0d9d5ff2d1018..45c937e2c4da93570e1a893479c9ef68635d0406 100644 --- a/src/client/configs/config.js +++ b/src/client/configs/config.js @@ -1 +1,5 @@ +export const rootUrl = ''; + +export const publishedPort = 3006; + export const MAPBOX_ACCESS_TOKEN = 'pk.eyJ1IjoiZWtrb25lbiIsImEiOiJjam5vampzZ28xd2dyM3BzNXR0Zzg4azl4In0.eozyF-bBaZbA3ibhvJlJpQ'; diff --git a/src/client/epics/index.js b/src/client/epics/index.js index cec3f8380eccd8399c655866128d29fe30d50091..c3a2ac6921c1273ab2d0cb997c5cf0033716616b 100644 --- a/src/client/epics/index.js +++ b/src/client/epics/index.js @@ -36,10 +36,16 @@ import { updateFacetValuesConstrainSelf, updateLocale } from '../actions'; +import { rootUrl, publishedPort } from '../configs/config'; + +// set port if running on localhost with NODE_ENV = 'production' +const port = location.hostname === 'localhost' || location.hostname === '127.0.0.1' + ? `:${publishedPort}` + : ''; export const apiUrl = (process.env.NODE_ENV === 'development') - ? 'http://localhost:3001/api/' - : `${location.protocol}//${location.hostname}/api/`; + ? `http://localhost:3001${rootUrl}/api/` + : `${location.protocol}//${location.hostname}${port}${rootUrl}/api/`; const backendErrorText = `Cannot connect to the MMM Knowledge Base. Please try again later.`;