diff --git a/backend/app/main.py b/backend/app/main.py index 84f54d38b..ee7d88a70 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -261,6 +261,9 @@ ) api_router.include_router(status.router, prefix="/status", tags=["status"]) api_router.include_router(keycloak.router, prefix="/auth", tags=["auth"]) + +if not settings.API_V2_STR.startswith("/"): + settings.API_V2_STR = "/" + settings.API_V2_STR app.include_router(api_router, prefix=settings.API_V2_STR) diff --git a/docker-compose.yml b/docker-compose.yml index 008b42fd6..7bbb02a55 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -65,7 +65,7 @@ services: frontend_url: http://localhost # For deploy to subdirectory BASE_URL_ROUTE: ${BASE_URL_ROUTE:-} - API_V2_STR: "/${BASE_URL_ROUTE}/api/v2" + API_V2_STR: "${BASE_URL_ROUTE}/api/v2" depends_on: - mongo - minio-nginx diff --git a/docs/docs/admins/deployatsubdirectory.md b/docs/docs/admins/deployatsubdirectory.md new file mode 100644 index 000000000..0dfec3901 --- /dev/null +++ b/docs/docs/admins/deployatsubdirectory.md @@ -0,0 +1,57 @@ +# Deploying Application to Subdirectory "clowder" + +This guide will walk you through the steps to deploy your frontend and backend applications to the +subdirectory `/clowder`, ensuring that both the frontend and backend are accessible under this path. + +## Step 1: Build the Frontend Image + +To deploy the frontend application under `/clowder`, build the Docker image with the appropriate build arguments: + +```bash +docker build --no-cache -t clowder/clowder2-frontend:basename \ + --build-arg BASE_URL_ROUTE=clowder \ + --build-arg CLOWDER_REMOTE_HOSTNAME="http://localhost/clowder" \ + . +``` + +- **`BASE_URL_ROUTE=clowder`**: Configures the frontend to operate under the `/clowder` subdirectory. +- **`CLOWDER_REMOTE_HOSTNAME=clowder`**: Point to the backend service that frontend will request, which should match + the subdirectory "/clowder" as well. + +## Step 2: Modify `docker-compose.yml` to Use the Built Image + +In your `docker-compose.yml`, update the frontend service to use the newly built image: + +```yaml +frontend: + image: "clowder/clowder2-frontend:basename" +``` + +This ensures that the correct image, configured for the `/clowder` subdirectory, is used when deploying. + +## Step 3: Set the `BASE_URL_ROUTE` Environment Variable + +Before running Docker Compose, make sure the `BASE_URL_ROUTE` environment variable is set to `clowder`. This ensures +that both the frontend and backend services are configured to operate under the `/clowder` subdirectory. + +```bash +export BASE_URL_ROUTE=clowder +echo $BASE_URL_ROUTE +``` + +- This environment variable ensures that the backend is also aware that it needs to operate under the `/clowder` + subdirectory. + +## Step 4: Start the Services with Docker Compose + +Now, start your services using Docker Compose: + +```bash +docker-compose up +``` + +- **Backend**: The backend service will be accessible at `http://localhost/clowder/api/v2`. +- **Frontend**: The frontend service will be accessible at `http://localhost/clowder`. + +By following these steps, both your backend and frontend services will be correctly deployed under the `/clowder` +subdirectory, making them accessible through the configured paths.