23 lines
525 B
Python
23 lines
525 B
Python
from fastapi import FastAPI
|
||
import uvicorn
|
||
from fastapi.responses import HTMLResponse
|
||
from pathlib import Path
|
||
|
||
app = FastAPI()
|
||
|
||
def run_with(app:FastAPI):
|
||
@app.get('/a')
|
||
def a():
|
||
return {'Hello': 'World'}
|
||
@app.get('/b')
|
||
def b():
|
||
return HTMLResponse(Path('static/b.html').read_bytes())
|
||
|
||
def main():
|
||
# 使用uvicorn运行FastAPI应用,指定主机地址和端口
|
||
|
||
run_with(app)
|
||
uvicorn.run(app, host="127.0.0.1", port=8000, log_level="info")
|
||
|
||
if __name__ == "__main__":
|
||
main() |