Skip to content

Commit

Permalink
added the base url to the workflows, client, and server
Browse files Browse the repository at this point in the history
  • Loading branch information
nickkats committed Feb 23, 2024
1 parent f6ff8e0 commit 3571df3
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ jobs:
env:
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
LOG_LEVEL: ${{ vars.SERVER_LOG_LEVEL }}
REACT_APP_API_SERVER: ${{ vars.REACT_APP_API_SERVER }}
REACT_APP_API_SERVER: ${{ vars.REACT_APP_API_SERVER }}
API_BASE_URL: ${{ vars.API_BASE_URL }}
2 changes: 2 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
LOG_LEVEL: ${{ vars.SERVER_LOG_LEVEL }}
REACT_APP_API_SERVER: ${{ vars.REACT_APP_API_SERVER }}
PUBLIC_URL: ${{ vars.PUBLIC_URL }}
API_BASE_URL: ${{ vars.API_BASE_URL }}


deploy:
Expand Down Expand Up @@ -83,3 +84,4 @@ jobs:
ARGO_CD_SERVER: ${{ secrets.ARGO_CD_SERVER }}
ARGO_CD_USERNAME: ${{ secrets.ARGO_CD_USERNAME }}
ARGO_CD_PASSWORD: ${{ secrets.ARGO_CD_PASSWORD }}
API_BASE_URL: ${{ vars.API_BASE_URL }}
4 changes: 2 additions & 2 deletions app/client/src/components/Mapbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ReactMapGL, { Marker, NavigationControl } from 'react-map-gl'
import '../assets/stylesheets/map.css'
import 'mapbox-gl/dist/mapbox-gl.css'
import mapImg from '../assets/img/UntitledMural_LocatedAtVeggielutionFarm_SanJose_photoby_YanYinChoy.jpg'

import { API_URL } from '../utils/API_URL';
// TODO: from process.env ?
const MAPBOX_TOKEN = 'pk.eyJ1IjoidW1hcHJlZXRoaSIsImEiOiJja3diNm5wN3RnZWhsMnZwZzlyeTl5eDhhIn0.01MGUHXlsnSkJbv1u-mbmw'

Expand All @@ -19,7 +19,7 @@ function Mapbox() {
// Calling MapData API to get data
const [apiData, setApiData] = React.useState([])
React.useEffect(() => {
fetch(`${process.env.REACT_APP_API_SERVER}/features`)
fetch(`${API_URL}/features`)
.then((res) => res.json())
.then((data) => setApiData(data))
}, [])
Expand Down
12 changes: 12 additions & 0 deletions app/client/src/utils/API_URL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function getApiUrl() {
const host = process.env.REACT_APP_API_SERVER;
const subDir = process.env.API_BASE_URL;
const url = new URL(subDir, host).toString();
if (url.endsWith('/')) {
return url.substring(0, url.length - 1);
}
return url;
}
module.exports = {
API_URL: getApiUrl(),
};
7 changes: 6 additions & 1 deletion docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ target "_common" {
* different dependent targets.
*/
// This builds the frontend bundle and serves using nginx
variable "API_BASE_URL" { default = "/v1/heartofvalley" }
variable "PUBLIC_URL" { default = "http://localhost" }
variable "REACT_APP_API_SERVER" { default = "http://localhost" }

Expand All @@ -86,6 +87,7 @@ target "build" {
NODE_VERSION = "${NODE_VERSION}"
PUBLIC_URL = "${PUBLIC_URL}"
REACT_APP_API_SERVER = "${REACT_APP_API_SERVER}"
API_BASE_URL = "${API_BASE_URL}"
}
inherits = ["_common"]
tags = dockerTag("${PROJECT_NAME}", "${DOCKER_TAG}", "frontend")
Expand All @@ -99,6 +101,8 @@ target "frontend" {
target = "dev"
args = {
NODE_VERSION = "${NODE_VERSION}"
REACT_APP_API_SERVER = "${REACT_APP_API_SERVER}"
API_BASE_URL = "${API_BASE_URL}"
}
inherits = ["_common"]
tags = dockerTag("${PROJECT_NAME}", "${DOCKER_TAG}", "frontend")
Expand All @@ -111,6 +115,7 @@ target "backend" {
context = "./"
args = {
NODE_VERSION = "${NODE_VERSION}"
API_BASE_URL = "${API_BASE_URL}"
}
inherits = ["_common"]
tags = dockerTag("${PROJECT_NAME}", "${DOCKER_TAG}", "backend")
Expand All @@ -124,5 +129,5 @@ target "backend" {
* "docker buildx bake" == "docker buildx bake default"
*/
group "default" {
targets = ["frontend", "backend"]
targets = ["build", "backend"]
}
5 changes: 4 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ services:
ports:
- "3000:3000"
environment:
REACT_APP_API_SERVER: "http://localhost:3001/v1/heartofvalley"
REACT_APP_API_SERVER: "http://localhost:3001"
API_BASE_URL: '/v1/heartofvalley'

backend:
build:
context: .
dockerfile: docker/backend/Dockerfile
args:
NODE_VERSION: ${NODE_VERSION}
environment:
API_BASE_URL: '/v1/heartofvalley'
volumes:
- ./app/server:/usr/src/app
- /usr/src/app/node_modules
Expand Down
1 change: 1 addition & 0 deletions docker/frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ FROM local as build
LABEL org.opensourcesanjose.app="heartofthevalley"
ARG PUBLIC_URL
ARG REACT_APP_API_SERVER
ARG API_BASE_URL
RUN npm run build

FROM nginx as nginx-build
Expand Down

0 comments on commit 3571df3

Please sign in to comment.