feat: add /health endpoint, migrate to lifespan lifecycle, and fix Dockerfile for production#439
Open
Arijit429 wants to merge 3 commits intofireform-core:mainfrom
Open
Conversation
- Add HTTPException handler for consistent error shape across all routes
- Add RequestValidationError handler with human-readable error messages
- Add catch-all Exception handler to prevent stack trace leakage
- Fix duplicate get_template() call in forms.py (was querying DB twice)
- Wrap Controller errors in AppError for safe client-facing messages
- All errors now return uniform {success, error: {code, message}} envelope
…file - Add GET /health liveness probe for Docker and container orchestration - Migrate database init from module-level to FastAPI lifespan context manager - Fix Dockerfile: start uvicorn server instead of tail -f /dev/null - Fix Dockerfile: correct PYTHONPATH from /app/src to /app - Add Docker HEALTHCHECK directive using /health endpoint - Add EXPOSE 8000 for container port documentation - Add FastAPI metadata (title, description, version) for API docs
Author
ContextThree deployment blockers fixed: added a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #116
Closes #118
Closes #122
Closes #135
Closes #187
Closes #274
Closes #388
Summary
Adds a health check endpoint for container orchestration, migrates database
initialization to FastAPI's modern lifespan pattern, and fixes the Dockerfile
to actually start the application server.
Problem
No health check — Docker, Kubernetes, and cloud platforms need a
/healthendpoint to monitor if the app is alive and auto-restart on failure.FireForm had no such endpoint.
Database init at import time —
Template.metadata.create_all()andFormSubmission.metadata.create_all()ran at the module top level, meaningdatabase tables were created whenever any file imported
main.py— includingduring test collection, linting, and static analysis. FastAPI's recommended
pattern uses
lifespancontext managers.Dockerfile doesn't start the app —
CMD ["tail", "-f", "/dev/null"]keepsthe container alive but does not run the server. PYTHONPATH was also set to
/app/srcinstead of/app, which would break imports.Changes
api/main.pyGET /healthendpoint returning{"status": "healthy", "service": "fireform"}lifespanasync context managercreate_all()callsDockerfile/app/srcto/appEXPOSE 8000HEALTHCHECKdirective using the/healthendpointTesting
GET /healthreturns expected JSON responseChanges Summary
api/main.pyGET /healthendpointapi/main.pylifespancontext managerapi/main.py/docspageDockerfileuvicorn api.main:apptail -f /dev/null)Dockerfile/app/src→/appDockerfileHEALTHCHECKdirectiveDockerfileEXPOSE 8000