| 12345678910111213141516171819202122232425 |
- import os
- from pathlib import Path
- from fastapi import FastAPI
- from fastapi.middleware.cors import CORSMiddleware
- from fastapi.responses import HTMLResponse
- from room_cal._utils import services as _services, service_name
- from room_cal.api._routes.calc import router as _calc_router
- _CALC_HTML = Path(__file__).parents[1] / 'vue' / 'calc.html'
- _API_BASE = os.getenv('APP_BASE_URL', '').rstrip('/')
- app = FastAPI(title='room_cal calc')
- app.add_middleware(CORSMiddleware, allow_origins=['*'], allow_methods=['*'], allow_headers=['*'])
- app.include_router(_calc_router)
- @app.get('/services')
- async def get_services():
- return [{'key': s, 'name': service_name(s)} for s in _services()]
- @app.get('/', response_class=HTMLResponse, include_in_schema=False)
- async def calc_ui():
- html = _CALC_HTML.read_text()
- return html.replace("const API_BASE = '';", f"const API_BASE = '{_API_BASE}';", 1)
|