Backend API prefix (#240)

* apply /api prefix consistently, both directly through backend and when accessing via frontend, fixes #236

* docs: update local deployment docs to use 9871 instead of 8000, don't expose 8000 by default

* schemas: don't include /openapi.json as /healthz in documentation, keep /healthz at root

* k8s: route backend to /api without additional rewriting
This commit is contained in:
Ilya Kreymer 2022-05-31 19:29:20 -07:00 committed by GitHub
parent 2355de3067
commit c023fe7c9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 13 deletions

View File

@ -16,7 +16,7 @@ Then, run `docker-compose build; docker-compose up -d` to launch.
To update/relaunch, use `./docker-restart.sh`. To update/relaunch, use `./docker-restart.sh`.
The API should be available at: `http://localhost:8000/docs` The API documentation should be available at: `http://localhost:9871/api/docs`.
To allow downloading of WACZ files via the UI from a remote host, set the `STORE_ACCESS_ENDPOINT_URL` to use the domain of the host. To allow downloading of WACZ files via the UI from a remote host, set the `STORE_ACCESS_ENDPOINT_URL` to use the domain of the host.
Otherwise, the files are accesible only through the default Minio service running on port 9000. Otherwise, the files are accesible only through the default Minio service running on port 9000.

View File

@ -8,5 +8,5 @@ RUN pip install -r requirements.txt
ADD . /app ADD . /app
CMD uvicorn main:app --host 0.0.0.0 --root-path /api --access-log --log-level info CMD uvicorn main:app_root --host 0.0.0.0 --access-log --log-level info

View File

@ -6,6 +6,8 @@ supports docker and kubernetes based deployments of multiple browsertrix-crawler
import os import os
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.routing import APIRouter
from fastapi.responses import JSONResponse
from db import init_db from db import init_db
@ -22,8 +24,14 @@ from colls import init_collections_api
from crawls import init_crawls_api from crawls import init_crawls_api
app = FastAPI() API_PREFIX = "/api"
app_root = FastAPI(
docs_url=API_PREFIX + "/docs",
redoc_url=API_PREFIX + "/redoc",
openapi_url=API_PREFIX + "/openapi.json",
)
app = APIRouter()
# ============================================================================ # ============================================================================
# pylint: disable=too-many-locals # pylint: disable=too-many-locals
@ -103,13 +111,21 @@ def main():
async def get_settings(): async def get_settings():
return settings return settings
@app.get("/healthz") # internal routes
@app.get("/openapi.json", include_in_schema=False)
async def openapi() -> JSONResponse:
return JSONResponse(app_root.openapi())
@app_root.get("/healthz", include_in_schema=False)
async def healthz(): async def healthz():
return {} return {}
app_root.include_router(app, prefix=API_PREFIX)
# ============================================================================ # ============================================================================
@app.on_event("startup") @app_root.on_event("startup")
async def startup(): async def startup():
"""init on startup""" """init on startup"""
main() main()

View File

@ -41,7 +41,7 @@ spec:
number: 9000 number: 9000
{{- end }} {{- end }}
- path: /api/(.*) - path: /(api/.*)
pathType: Prefix pathType: Prefix
backend: backend:
service: service:

View File

@ -55,7 +55,7 @@ stringData:
STORE_ACCESS_ENDPOINT_URL: "{{ $storage.endpoint_url }}" STORE_ACCESS_ENDPOINT_URL: "{{ $storage.endpoint_url }}"
{{- end }} {{- end }}
STORE_REGION: {{ $storage.region | default "" }} STORE_REGION: "{{ $storage.region }}"
{{- if $.Values.signer.auth_token }} {{- if $.Values.signer.auth_token }}
WACZ_SIGN_TOKEN: "{{ $.Values.signer.auth_token }}" WACZ_SIGN_TOKEN: "{{ $.Values.signer.auth_token }}"

View File

@ -15,8 +15,9 @@ services:
- mongo - mongo
- volume_placeholder_image - volume_placeholder_image
ports: # enable to expose backend api container directly
- 8000:8000 # ports:
# - 8000:8000
frontend: frontend:
build: ./frontend build: ./frontend
@ -34,9 +35,6 @@ services:
image: redis image: redis
command: redis-server --appendonly yes command: redis-server --appendonly yes
#ports:
# - 6379:6379
volumes: volumes:
- btrix-redis-data:/data - btrix-redis-data:/data

View File

@ -32,7 +32,7 @@ server {
# used by docker only: k8s deployment handles /api directly via ingress # used by docker only: k8s deployment handles /api directly via ingress
location /api/ { location /api/ {
proxy_pass http://${BACKEND_HOST}:8000/; proxy_pass http://${BACKEND_HOST}:8000;
proxy_set_header Host $http_host; proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
} }