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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,13 @@ Notes:
into documentation for ReadTheDocs works as expected. For more information, see
the Python Project Template documentation on
[Sphinx and Python Notebooks](https://lincc-ppt.readthedocs.io/en/latest/practices/sphinx.html#python-notebooks)

## Running the TAP server with gunicorn

Install the optional server extra (or install `gunicorn` separately), then run gunicorn
against the provided WSGI callable:

```
pip install 'hats-tap[server]'
gunicorn "hats_tap.tap_server:application" --bind 0.0.0.0:43213
```
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ dev = [
"pytest-cov", # Used to report total code coverage
"ruff", # Used for static linting of files
]
server = [
"gunicorn>=22.0.0", # Optional WSGI server for production use
]

[build-system]
requires = [
Expand Down
9 changes: 9 additions & 0 deletions src/hats_tap/tap_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
app = Flask(__name__)


def create_app():
"""Return the Flask application for use with WSGI servers such as gunicorn."""
return app


# Default WSGI callable name expected by gunicorn when no object is specified.
application = app


# Log what the client is actually sending
@app.before_request
def log_request_info():
Expand Down
10 changes: 10 additions & 0 deletions tests/hats_tap/test_tap_server_wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Tests for WSGI compatibility of the TAP server."""

from hats_tap import tap_server


def test_wsgi_app_exports():
"""The tap_server module should expose a WSGI callable for gunicorn."""
wsgi_app = tap_server.create_app()
assert wsgi_app is tap_server.app
assert tap_server.application is tap_server.app
Loading