Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
LINT_IMAGE := rhysd/actionlint@sha256:b1934ee5f1c509618f2508e6eb47ee0d3520686341fec936f3b79331f9315667
LINT_RUN := docker run --rm -v "$(CURDIR):/repo" -w /repo

# Install all deps for local work.
setup:
cd backend && uv sync
cd frontend && npm ci
Expand Down
3 changes: 2 additions & 1 deletion backend/app/api/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
router = APIRouter()


# The container health check and the deploy.sh rollback call this path. Do not move it.
@router.get("/health")
def health() -> dict[str, str]:
def get_health() -> dict[str, str]:
return {"status": "ok"}
5 changes: 4 additions & 1 deletion backend/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
class Settings(BaseSettings):
# Root .env for `make dev-be` (cwd is backend/). Missing files are skipped, and in
# Docker the values come from Compose env_file instead.
model_config = SettingsConfigDict(env_file=("../.env", ".env"), extra="ignore")
model_config = SettingsConfigDict(
env_file=("../.env", ".env"),
extra="ignore",
)

app_name: str = "junction-2026"
5 changes: 4 additions & 1 deletion backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
def create_app(settings: Settings | None = None) -> FastAPI:
settings = settings or Settings()
app = FastAPI(title=settings.app_name)
app.include_router(health.router, prefix=_API_PREFIX)
app.include_router(
health.router,
prefix=_API_PREFIX,
)
return app


Expand Down
5 changes: 4 additions & 1 deletion backend/tests/test_health.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from http import HTTPStatus

from fastapi.testclient import TestClient

from app.main import create_app


def test_health_returns_ok() -> None:
"""Deploy waits for this route to be healthy and rolls back when it is not."""
client = TestClient(create_app())

response = client.get("/api/health")

assert response.status_code == 200
assert response.status_code == HTTPStatus.OK
assert response.json() == {"status": "ok"}
6 changes: 3 additions & 3 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { useEffect, useState, type ReactElement } from 'react'

import { getHealth } from './api.ts'
import { getHealth, type BackendHealth } from './api.ts'

type BackendStatus = 'loading' | 'ok' | 'down'
type BackendStatus = 'loading' | BackendHealth

export function App(): ReactElement {
const [status, setStatus] = useState<BackendStatus>('loading')

useEffect(() => {
getHealth()
.then((health) => {
setStatus(health.status === 'ok' ? 'ok' : 'down')
setStatus(health)
})
.catch(() => {
setStatus('down')
Expand Down
13 changes: 10 additions & 3 deletions frontend/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
// Single place that talks to the backend. Caddy (prod) and the Vite proxy (dev)
// route /api/* to FastAPI, so relative paths work in both.
const API_BASE = '/api'
const HEALTHY_STATUS = 'ok'

export interface Health {
interface HealthResponse {
readonly status: string
}

export async function getHealth(): Promise<Health> {
export type BackendHealth = 'ok' | 'down'

export async function getHealth(): Promise<BackendHealth> {
const response = await fetch(`${API_BASE}/health`)

if (!response.ok) {
throw new Error(`Health check failed: ${response.status}`)
}
return (await response.json()) as Health

const body = (await response.json()) as HealthResponse

return body.status === HEALTHY_STATUS ? 'ok' : 'down'
}
Loading