Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Add documentation for accessing API over HTTPS (#2201)
Dhruv Bhanushalibdb8f0ad1dd0
diff --git a/api/justfile b/api/justfileindex c5e1afa77..60357abc6 100644--- a/api/justfile+++ b/api/justfile@@ -71,12 +71,12 @@ recreate:######### Make a cURL GET request to service at the given path-_curl-get path host="localhost:50280":- curl "http://{{ host }}/v1/{{ path }}"+_curl-get path origin="http://localhost:50280":+ curl "{{ origin }}/v1/{{ path }}"# Make a test cURL GET request to the API-stats media="images" host="localhost:50280":- just _curl-get "{{ media }}/stats/" {{ host }}+stats media="images" origin="http://localhost:50280":+ just _curl-get "{{ media }}/stats/" {{ origin }}# Launch a `pgcli` shell in the web containerpgcli db_user_pass="deploy" db_name="openledger": updiff --git a/docker/nginx/justfile b/docker/nginx/justfileindex 7392c3bad..80d593479 100644--- a/docker/nginx/justfile+++ b/docker/nginx/justfile@@ -12,8 +12,8 @@ NO_COLOR := "\\033[0m"# Make locally trusted certificates (requires mkcert installed)cert:- mkdir -p nginx/certs/+ mkdir -p certs/mkcert \- -cert-file nginx/certs/openverse.crt \- -key-file nginx/certs/openverse.key \+ -cert-file certs/openverse.crt \+ -key-file certs/openverse.key \dev.openverse.test localhost 127.0.0.1 ::1diff --git a/documentation/api/guides/https.md b/documentation/api/guides/https.mdnew file mode 100644index 000000000..13d4d3cd0--- /dev/null+++ b/documentation/api/guides/https.md@@ -0,0 +1,48 @@+# Local HTTPS testing++To access the API over HTTPS, we need to proxy to it using NGINX. Note that this+proxy is different from the API NGINX image that is specifically aimed at+serving static files in live environments.++## Prerequisites++Make sure you have gone through the+[quickstart guide](/api/guides/quickstart.md) before attempting this as this is+a slightly more advanced process.++Additionally, you will need to install+[mkcert](/general/general_setup.md#mkcert) as described in the+[general setup guide](/general/general_setup.md).++## Steps++1. Create certificates for NGINX to use.++ ```console+ $ just docker/nginx/cert+ ```++ This will create a certificate file `openversse.crt` and a key file+ `openverse.key` in the `docker/nginx/certs/` directory.++2. Bring the ingestion server and API up, along with all their dependent+ services.++ ```console+ $ just api/up+ ```++ The `api/up` recipe orchestrates the following services: `cache`, `db`,+ `upstream_db`, `es`, `indexer_worker`, `ingestion_server`, `web` and `proxy`.++ Note that the `proxy` service here is the NGINX instance that will handle our+ HTTPS requests.++3. Make an API call over HTTPS.++ ```console+ $ just api/stats images https://localhost:50243+ just _curl-get "images/stats/" https://localhost:50243+ curl "https://localhost:50243/v1/images/stats/"+ [{"source_name":"flickr","display_name":"Flickr","source_url":"https://www.flickr.com","logo_url":null,"media_count":2500},{"source_name":"stocksnap","display_name":"StockSnap","source_url":"https://stocksnap.io","logo_url":null,"media_count":2500}]%+ ```diff --git a/documentation/api/guides/index.md b/documentation/api/guides/index.mdindex 5042a4da7..b8d2ab8eb 100644--- a/documentation/api/guides/index.md+++ b/documentation/api/guides/index.md@@ -5,4 +5,5 @@quickstarttest+https```diff --git a/documentation/api/guides/quickstart.md b/documentation/api/guides/quickstart.mdindex 3f0e8cbe8..1efaf7de1 100644--- a/documentation/api/guides/quickstart.md+++ b/documentation/api/guides/quickstart.md@@ -67,7 +67,7 @@ you need to run this.```console$ just api/stats- just _curl-get "images/stats/" localhost:50280+ just _curl-get "images/stats/" http://localhost:50280curl "http://localhost:50280/v1/images/stats/"[{"source_name":"flickr","display_name":"Flickr","source_url":"https://www.flickr.com","logo_url":null,"media_count":2500},{"source_name":"stocksnap","display_name":"StockSnap","source_url":"https://stocksnap.io","logo_url":null,"media_count":2500}]%```diff --git a/documentation/general/quickstart.md b/documentation/general/quickstart.mdindex 75387a52d..31f3f6465 100644--- a/documentation/general/quickstart.md+++ b/documentation/general/quickstart.md@@ -130,7 +130,7 @@ prerequisites.```console$ just api/stats- just _curl-get "images/stats/" localhost:50280+ just _curl-get "images/stats/" http://localhost:50280curl "http://localhost:50280/v1/images/stats/"[{"source_name":"flickr","display_name":"Flickr","source_url":"https://www.flickr.com","logo_url":null,"media_count":2500},{"source_name":"stocksnap","display_name":"StockSnap","source_url":"https://stocksnap.io","logo_url":null,"media_count":2500}]%```diff --git a/justfile b/justfileindex 01a96be39..c383721a1 100644--- a/justfile+++ b/justfile@@ -244,6 +244,10 @@ a:c:just catalog/up+# alias for `just documentation/live`, 's' for Sphinx+s:+ just documentation/live+# alias for `just ingestion_server/up`i:just ingestion_server/updiff --git a/utilities/ps.py b/utilities/ps.pyindex cdf1d7a66..5d6e0b347 100644--- a/utilities/ps.py+++ b/utilities/ps.py@@ -20,9 +20,9 @@ class Service:print(f"\033[1m{self.name} ({self.image}):\033[0m")for host_port, container_port in self.bindings:proto = "http"- if self.name == "proxy" and container_port == 9443:+ if self.name == "proxy" and container_port == "9443":proto = "https"- print(f"- {proto:>5}://0.0.0.0:{host_port} (→ {container_port})")+ print(f"- {proto:>5}://0.0.0.0:{host_port:<5} (→ {container_port})")def get_ps() -> list[str]: