|
29 | 29 | app_public = FastAPI() |
30 | 30 | app_internal = FastAPI() |
31 | 31 |
|
32 | | -_INGRESS_LOCATION: str = os.getenv("INGRESS_LOCATION") |
33 | | -assert _INGRESS_LOCATION, "INGRESS_LOCATION environment variable must be set" |
| 32 | +# Configuration... |
| 33 | +_INGRESS_LOCATION: str = os.getenv("WS_INGRESS_LOCATION", "localhost:8080") |
| 34 | +assert _INGRESS_LOCATION, "WS_INGRESS_LOCATION environment variable must be set" |
| 35 | +_INGRESS_SECURE: bool = os.getenv("WS_INGRESS_SECURE", "no").lower() == "yes" |
| 36 | +_LOGGER.info("INGRESS_LOCATION: %s", _INGRESS_LOCATION) |
| 37 | +_LOGGER.info("INGRESS_SECURE: %s", _INGRESS_SECURE) |
34 | 38 |
|
35 | 39 | _AMPQ_EXCHANGE: str = "event-streams" |
36 | | -_AMPQ_URL: str = os.getenv("AMPQ_URL") |
37 | | -assert _AMPQ_URL, "AMPQ_URL environment variable must be set" |
| 40 | +_AMPQ_URL: str = os.getenv("WS_AMPQ_URL", "") |
| 41 | +assert _AMPQ_URL, "WS_AMPQ_URL environment variable must be set" |
38 | 42 | _LOGGER.info("AMPQ_URL: %s", _AMPQ_URL) |
39 | 43 |
|
40 | 44 | # Create our local database. |
|
43 | 47 | # value when NONE is passed in as it's value. |
44 | 48 | _DATABASE_PATH = "/data/event-streams.db" |
45 | 49 | _LOGGER.info("Creating SQLite database (%s)...", _DATABASE_PATH) |
46 | | - |
47 | 50 | _DB_CONNECTION = sqlite3.connect(_DATABASE_PATH) |
48 | 51 | _CUR = _DB_CONNECTION.cursor() |
49 | 52 | _CUR.execute( |
50 | 53 | "CREATE TABLE IF NOT EXISTS es (id INTEGER PRIMARY KEY, uuid TEXT, routing_key TEXT)" |
51 | 54 | ) |
52 | 55 | _DB_CONNECTION.commit() |
53 | 56 | _DB_CONNECTION.close() |
54 | | - |
55 | 57 | _LOGGER.info("Created.") |
56 | 58 |
|
57 | 59 |
|
@@ -139,8 +141,11 @@ def post_es(request_body: EventStreamPostRequestBody): |
139 | 141 | and an ID the event stream is known by (that can be used to delete the stream). |
140 | 142 | In our case, it's a WebSocket URL like 'ws://localhost:8000/event-stream/0000'. |
141 | 143 | """ |
| 144 | + # Generate am new (difficult to guess) UUID for the event stream... |
142 | 145 | uuid_str: str = shortuuid.uuid() |
143 | | - location: str = f"ws://{_INGRESS_LOCATION}/event-stream/{uuid_str}" |
| 146 | + # And construct the location we'll be listening on... |
| 147 | + location: str = "wss://" if _INGRESS_SECURE else "ws://" |
| 148 | + location += f"{_INGRESS_LOCATION}/event-stream/{uuid_str}" |
144 | 149 |
|
145 | 150 | # Create a new ES record... |
146 | 151 | # An ID is assigned automatically - |
|
0 commit comments