forked from mabdullahadeel/vercel-fastapi-deployment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
35 lines (31 loc) · 966 Bytes
/
main.py
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
from time import time
from fastapi import FastAPI, __version__
from fastapi.staticfiles import StaticFiles
from fastapi.responses import HTMLResponse
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
html = f"""
<!DOCTYPE html>
<html>
<head>
<title>FastAPI on Vercel</title>
<link rel="icon" href="/static/favicon.ico" type="image/x-icon" />
</head>
<body>
<div class="bg-gray-200 p-4 rounded-lg shadow-lg">
<h1>Hello from FastAPI@{__version__}</h1>
<ul>
<li><a href="/docs">/docs</a></li>
<li><a href="/redoc">/redoc</a></li>
</ul>
<p>Powered by <a href="https://vercel.com" target="_blank">Vercel</a></p>
</div>
</body>
</html>
"""
@app.get("/")
async def root():
return HTMLResponse(html)
@app.get('/ping')
async def hello():
return {'res': 'pong', 'version': __version__, "time": time()}