My DIY fitness tracker journey. Frontend is built using Vue.js and Bootstrap CSS; Python FastAPI, Alembic, SQLAlchemy, stravalib, gpxpy, MariaDB behind the scenes. Suggestions welcome!
GNU General Public License v3.0
646
stars
14
forks
source link
Frontend cannot connect to backend using Docker #50
I am trying to setup Endurain in a Docker environment and all is well until I try to login to the frontend. This fails with a CORS error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://localhost:98/api/v1/token. (Reason: CORS request did not succeed). Status code: (null).
The problem here is that it does not run on localhost but it runs on domain endurain_backend. Now I tried also to modify the docker-compose file with the IP address of the Docker container but it still tries to connect on localhost. When I am inside the endurain_frontend container I can ping the endurain_backend using that hostname, so there is connectivity.
So the question I guess is, why does it try to connect on localhost when another host has been configured?
Edit: I now have that it keeps trying to connect to endurain_backend which is not correct either as I figured because those domain names are not reachable outside of the local network. So I have updated my compose file and replaced the actual domain with DOMAIN below.
This gives me the feeling something is cached so I will have another look later.
Let me know if I missed any information.
Here is the docker-compose I am using:
services:
# frontend logic
frontend:
container_name: endurain_frontend
image: ghcr.io/joaovitoriasilva/endurain/frontend:latest
environment:
- MY_APP_BACKEND_PROTOCOL=https # http or https, default is http
- MY_APP_BACKEND_HOST=https://DOMAIN # api host or local ip (example: 192.168.1.10:98), default is localhost:98
- MY_APP_STRAVA_CLIENT_ID=${STRAVA_CLIENT_ID}
# Configure volume if you want to edit the code locally by clomming the repo
#volumes:
# - <local_path>/endurain/frontend/app:/app
ports:
- "8124:80" # frontend port, change per your needs
restart: unless-stopped
networks:
- endurain
- galaxy
# API logic
backend:
container_name: endurain_backend
image: ghcr.io/joaovitoriasilva/endurain/backend:latest
environment:
- DB_PASSWORD=${DB_PASSWORD}
- SECRET_KEY=${SECRET_KEY} # openssl rand -hex 32
- STRAVA_CLIENT_ID=${STRAVA_CLIENT_ID}
- STRAVA_CLIENT_SECRET=${STRAVA_CLIENT_SECRET}
- STRAVA_AUTH_CODE=${STRAVA_AUTH_CODE}
- GEOCODES_MAPS_API=
- FRONTEND_PROTOCOL=https # default is http
- FRONTEND_HOST=https://DOMAIN # frontend host or local ip (example: 192.168.1.10:8080), default is localhost:8080
ports:
- "98:80" # API port, change per your needs
volumes:
# - <local_path>/endurain/backend/app:/app # Configure volume if you want to edit the code locally by cloning the repo
- ${UPLOAD_LOCATION}/endurain/backend/user_images:/app/user_images # necessary for user image persistence on container image updates
- ${UPLOAD_LOCATION}/endurain/backend/files/bulk_import:/app/files/bulk_import # necessary to enable bulk import of activities. Place here your activities files
- ${UPLOAD_LOCATION}/endurain/backend/files/processed:/app/files/processed # necessary for processed original files persistence on container image updates
- ${UPLOAD_LOCATION}/endurain/backend/logs:/app/logs # log files for the backend
depends_on:
- mariadb
restart: unless-stopped
networks:
- endurain
- galaxy
# mysql mariadb logic
mariadb:
image: mariadb:latest
container_name: endurain_mariadb
environment:
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
- MYSQL_DATABASE=endurain
- MYSQL_USER=endurain
- MYSQL_PASSWORD=${DB_PASSWORD}
ports:
- "3306:3306"
volumes:
- ${UPLOAD_LOCATION}/mariadb:/var/lib/mysql
restart: unless-stopped
networks:
- endurain
networks:
endurain:
external: false
galaxy:
external: true
However I think the problem is the urls are not being properly built:
Frontend - MY_APP_BACKEND_HOST should be the host the frontend will use to communicate with the backend. So if it is local only, it can be the ip_address:port like localhost:98 or 192.168.1.10:98 or api.endurain.local. Example screenshot bellow:
Backend - FRONTEND_HOST should be what you place in the browser to access the frontend. So if it is local only, it can be the ip_address:port like localhost:5173 or 192.168.1.10:5173 or endurain.local. Example screenshot bellow:
Hi,
I am trying to setup Endurain in a Docker environment and all is well until I try to login to the frontend. This fails with a CORS error:
The problem here is that it does not run on localhost but it runs on domain
endurain_backend
. Now I tried also to modify the docker-compose file with the IP address of the Docker container but it still tries to connect on localhost. When I am inside theendurain_frontend
container I can ping theendurain_backend
using that hostname, so there is connectivity.So the question I guess is, why does it try to connect on localhost when another host has been configured?
Edit: I now have that it keeps trying to connect to
endurain_backend
which is not correct either as I figured because those domain names are not reachable outside of the local network. So I have updated my compose file and replaced the actual domain with DOMAIN below.This gives me the feeling something is cached so I will have another look later.
Let me know if I missed any information.
Here is the docker-compose I am using: