added redirect service

This commit is contained in:
Helva
2026-02-14 11:21:26 +01:00
parent d3b274e205
commit 8ccb7d21dd
5 changed files with 57 additions and 5 deletions
+8
View File
@@ -2,6 +2,14 @@ server {
listen 80;
server_name _;
# redirect service to tethering IP for 'webview kiosk' -> mobile phone to face
location /redirect {
proxy_pass http://127.0.0.1:8000/redirect;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# captive portal to face
include /opt/helva-robot/drive/etc/nginx/snippets/captive-portal.conf;
+17
View File
@@ -0,0 +1,17 @@
[Unit]
Description=Redirect Tethering IP Service
After=network.target
[Service]
WorkingDirectory=/opt/face
ExecStart=/opt/face/venv/bin/python -m uvicorn redirect_tethering_ip:app --host 127.0.0.1 --port 8000 --app-dir /opt/face
Restart=always
RestartSec=1
# Tipp: eigener User ist sauber, aber www-data geht auch.
User=www-data
Group=www-data
[Install]
WantedBy=multi-user.target
+10
View File
@@ -66,6 +66,10 @@ async def broadcast() -> None:
async def get_state():
return JSONResponse(STATE)
@app.get("/api/state")
async def get_state():
return JSONResponse(STATE)
@app.post("/state")
async def set_state(payload: Dict[str, Any]):
@@ -73,6 +77,12 @@ async def set_state(payload: Dict[str, Any]):
await broadcast()
return JSONResponse({"ok": True, "state": STATE})
@app.post("/api/state")
async def set_state(payload: Dict[str, Any]):
merge_state(payload)
await broadcast()
return JSONResponse({"ok": True, "state": STATE})
@app.get("/events")
async def events(request: Request):
+14
View File
@@ -0,0 +1,14 @@
from fastapi import FastAPI
from fastapi.responses import RedirectResponse
import netifaces
app = FastAPI()
@app.get("/redirect")
def redirect_to_pi():
# gather tethering IP
interface = 'usb0'
ip_address = netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['addr']
# relocate to current tethering-IP
return RedirectResponse(url=f'http://{ip_address}:80')