-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
41 lines (29 loc) · 915 Bytes
/
main.py
File metadata and controls
41 lines (29 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import importlib
import os
from fastapi import FastAPI
from starlette.responses import RedirectResponse
api_version = "Unknown"
routes = []
for file in sorted(os.listdir("api")):
if file.endswith(".py"):
name = file[:-3]
api_version = name
module = importlib.import_module(f"api.{name}")
routes.append((name, module.router))
app = FastAPI(
title="Time API",
description="""
A simple API for getting the current time. You can use this for devices that don't have a clock.
- [GitHub](https://github.com/dodaucy/time-api)
- [Swagger Documentation](/)
- [Redoc Documentation](/redoc)
""".strip(),
version=api_version,
docs_url="/",
redoc_url="/redoc"
)
@app.get("/docs", include_in_schema=False)
async def docs_redirect():
return RedirectResponse("/")
for name, router in routes:
app.include_router(router, prefix=f"/{name}", tags=[name])