42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
import socket
|
|
|
|
import uvicorn
|
|
|
|
from . import config
|
|
|
|
|
|
def lan_ip():
|
|
try:
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
s.connect(("10.255.255.255", 1))
|
|
return s.getsockname()[0]
|
|
except OSError:
|
|
return "127.0.0.1"
|
|
|
|
|
|
def main():
|
|
scheme = "https" if config.TLS_CERT else "http"
|
|
# "RUNNING" is the ready marker the pelican python egg waits for
|
|
print(f"RotatyVote RUNNING on {scheme}://localhost:{config.PORT} (LAN: {scheme}://{lan_ip()}:{config.PORT})", flush=True)
|
|
if config.PUBLIC_URL:
|
|
print(f"QR codes encode {config.PUBLIC_URL}")
|
|
elif scheme == "http":
|
|
print("warning: phones need HTTPS for the camera. set TLS_CERT/TLS_KEY or put a TLS proxy in front")
|
|
uvicorn.run(
|
|
"rotatyvote.app:app",
|
|
host=config.HOST,
|
|
port=config.PORT,
|
|
ssl_certfile=config.TLS_CERT or None,
|
|
ssl_keyfile=config.TLS_KEY or None,
|
|
proxy_headers=config.BEHIND_PROXY,
|
|
forwarded_allow_ips="*" if config.BEHIND_PROXY else None,
|
|
ws="websockets-sansio",
|
|
# access + websocket "connection open" lines would leak per-ip timing
|
|
access_log=False,
|
|
log_level="warning",
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|