Skip to content

Commit

Permalink
Fixing geolocation on production plus configuring maxmind to run loca…
Browse files Browse the repository at this point in the history
…lly (#278)

* Changing docker container to run maxmind locally

* Adding files for local geolocation
  • Loading branch information
sylviamclaughlin authored Sep 27, 2023
1 parent 3223cc7 commit 2d693cf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
7 changes: 1 addition & 6 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,4 @@ RUN echo "\n\
[default]\n\
region=ca-central-1\n\
output=json\n\
" >> /home/vscode/.aws/config

# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image.
# COPY requirements.txt /tmp/pip-tmp/
# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
# && rm -rf /tmp/pip-tmp
" >> /home/vscode/.aws/config
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
//use postcommand to create the maxmind db
'postCreateCommand': '.devcontainer/maxmind-create.sh',
"remoteUser": "vscode",
"features": {
"ghcr.io/devcontainers/features/aws-cli:1": {
Expand Down
6 changes: 6 additions & 0 deletions .devcontainer/maxmind-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mkdir -p /workspace/app/geodb/
wget -O "/workspace/app/geodb/GeoLite2-City.tar.gz" "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=$MAXMIND_KEY&suffix=tar.gz"
tar -xzvf /workspace/app/geodb/GeoLite2-City.tar.gz -C /workspace/app/geodb/
cp /workspace/app/geodb/GeoLite2-City_*/GeoLite2-City.mmdb /workspace/app/geodb/GeoLite2-City.mmdb
rm -fr /workspace/app/geodb/GeoLite2-City_*
rm /workspace/app/geodb/GeoLite2-City.tar.gz
21 changes: 17 additions & 4 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/src/scenes/geolocate/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const geoUrl =
// call the backend API to fetch the location data using the /geolocate endpoint
// if we are in development we need to call the API using the full URL
function fetchLocationData(inputValue) {
return fetch(process.env.REACT_APP_API_URL + '/geolocate/' + inputValue);
return fetch(`${window.origin}/geolocate/${inputValue}`);
}

function Geolocate() {
Expand Down

0 comments on commit 2d693cf

Please sign in to comment.