Skip to content

Commit

Permalink
add index.html to api, fix virtualio.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgineer85 committed Nov 1, 2024
1 parent 5b5aa11 commit aba3b2d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
5 changes: 5 additions & 0 deletions node/app_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
from contextlib import asynccontextmanager
from pathlib import Path

import uvicorn
from fastapi import FastAPI
Expand All @@ -13,6 +14,7 @@
from .common_utils import create_basic_folders
from .container import container
from .routers import api
from .routers.static import static_router

logger = logging.getLogger(f"{__name__}")

Expand Down Expand Up @@ -46,9 +48,12 @@ def _create_app() -> FastAPI:
dependencies=[],
lifespan=lifespan,
)
_app.include_router(static_router)
_app.include_router(api.router)
# serve data directory holding images, thumbnails, ...
_app.mount("/media", StaticFiles(directory="media"), name="media")
# if not match anything above, default to deliver static files from web directory
_app.mount("/", StaticFiles(directory=Path(__file__).parent.resolve().joinpath("web_spa")), name="web_spa")

async def custom_http_exception_handler(request, exc):
logger.error(f"HTTPException: {repr(exc)}")
Expand Down
29 changes: 9 additions & 20 deletions node/routers/static.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
import logging
from pathlib import Path

from fastapi import APIRouter
from fastapi.responses import FileResponse

logger = logging.getLogger(__name__)
static_router = APIRouter(
tags=["static"],
)


# @static_router.get("/")
# def index():
# """
# return homepage of booth
# """
# headers = {"Cache-Control": "no-store, no-cache, must-revalidate"}
# return FileResponse(path=Path(__file__).parent.parent.joinpath("web_spa", "index.html").resolve(), headers=headers)


# @static_router.get("/private.css")
# def ui_private_css():
# """
# if private.css exists return the file content, otherwise send empty response to avoid 404
# """
# path = Path("userdata", "private.css")
# headers = {"Cache-Control": "no-store, no-cache, must-revalidate"}
# if not path.is_file():
# return Response("/* placeholder. create private.css in userdata folder to customize css */", headers=headers)
# else:
# return FileResponse(path=path, headers=headers)
@static_router.get("/")
def index():
"""
return homepage of booth, index is special not cached so spa updates are less a problem
"""
headers = {"Cache-Control": "no-store, no-cache, must-revalidate"}
return FileResponse(path=Path(__file__).parent.parent.joinpath("web_spa", "index.html").resolve(), headers=headers)
2 changes: 1 addition & 1 deletion node/services/backends/io/virtualio.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _gpio_fun(self):

while not current_thread().stopped():
time.sleep((1.0 / self._config.fps_nominal) / 2.0)
self._on_clock_rise_in()
self._on_clock_rise_in(time.monotonic_ns())
time.sleep((1.0 / self._config.fps_nominal) / 2.0)
self._on_clock_fall_in()

Expand Down
21 changes: 21 additions & 0 deletions node/web_spa/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!doctype html>
<html>
<head>
<title>Photobooth-App</title>
<meta charset=utf-8>
<meta name=description content="wigglecam-api frontend">
<meta name=viewport content="user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1,width=device-width">
<meta name=mobile-web-app-capable content=yes>
<meta name=apple-mobile-web-app-capable content=yes>
</head>
<body>
<div>
<h1>Wigglecam-Api Frontend</h1>
<p>The api is just a backend with no actual frontend. This is just a collection of links, that might be helpful:</p>
<ul>
<li><a href="/api/doc">API docs</a></li>
<li><a href="/api/acquisition/stream.mjpg">Nodes Livestream</a></li>

</ul>
</div>
</body></html>

0 comments on commit aba3b2d

Please sign in to comment.