core.py 705 B

123456789101112131415161718192021222324252627282930
  1. import os
  2. import dotenv
  3. import fastapi
  4. import fastapi.staticfiles
  5. import fastapi.responses
  6. import assets
  7. dotenv.load_dotenv()
  8. print("Loading cx-notes...")
  9. print("Note name:", os.getenv("notes_name"))
  10. print("Database:", os.getenv("database"))
  11. api = fastapi.FastAPI()
  12. static = fastapi.staticfiles.StaticFiles(directory = "./static")
  13. database = assets.storage(os.getenv("database"))
  14. app = assets.notes(os.getenv("notes_name"), database)
  15. api.mount("/static/", static)
  16. @api.get("/", response_class = fastapi.responses.HTMLResponse)
  17. async def index():
  18. try:
  19. with open("./static/core.html") as index:
  20. return index.read()
  21. except:
  22. return "Error 404. Can not open file."