+import uvicorn
from fastapi import FastAPI, Request, HTTPException, responses
import sqlite3
from hashlib import sha256
from fastapi.templating import Jinja2Templates
from requests import get
+from json import loads
-base_url = ""
+with open("config.json") as f:
+ config = loads(f.read())
+ base_url = config["base_url"]
+ port = config["port"]
app = FastAPI(docs_url=base_url+"/docs", redoc_url=base_url+"/redoc")
templates = Jinja2Templates(directory=".")
def index(request: Request, domain: str = None):
if domain == "":
return responses.RedirectResponse("/")
- blocks = get(f"http://127.0.0.1:8069{base_url}/api?domain={domain}")
+ blocks = get(f"http://127.0.0.1:{port}{base_url}/api?domain={domain}")
info = None
if domain == None:
- info = get(f"http://127.0.0.1:8069{base_url}/info")
+ info = get(f"http://127.0.0.1:{port}{base_url}/info")
if not info.ok:
raise HTTPException(status_code=info.status_code, detail=info.text)
info = info.json()
if not blocks.ok:
raise HTTPException(status_code=blocks.status_code, detail=blocks.text)
return templates.TemplateResponse("index.html", {"request": request, "domain": domain, "blocks": blocks.json(), "info": info})
+
+if __name__ == "__main__":
+ uvicorn.run("api:app", host="127.0.0.1", port=port, log_level="info")