| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
import asyncio |
| 4 |
from http import HTTPStatus |
| 5 |
from websockets.asyncio.server import serve |
| 6 |
|
| 7 |
def health_check(connection, request): |
| 8 |
if request.path == "/healthz": |
| 9 |
return connection.respond(HTTPStatus.OK, "OK\n") |
| 10 |
|
| 11 |
async def echo(websocket): |
| 12 |
async for message in websocket: |
| 13 |
await websocket.send(message) |
| 14 |
|
| 15 |
async def main(): |
| 16 |
server = await serve(echo, "localhost", 8765, process_request=health_check) |
| 17 |
await server.serve_forever() |
| 18 |
|
| 19 |
asyncio.run(main()) |