Spaces:
Sleeping
Sleeping
Commit ·
7a86764
1
Parent(s): 826fe3a
change dir.
Browse files- app.py +0 -11
- fastapi/app.py +19 -0
- scripts/start.sh +1 -1
app.py
DELETED
|
@@ -1,11 +0,0 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
|
| 3 |
-
app = FastAPI()
|
| 4 |
-
|
| 5 |
-
@app.get("/")
|
| 6 |
-
def greet_json():
|
| 7 |
-
return {"Hello": "Node World!"}
|
| 8 |
-
|
| 9 |
-
@app.get("/hello/")
|
| 10 |
-
def hello_json():
|
| 11 |
-
return {"Hello": "FastAPI Node World!"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fastapi/app.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
|
| 3 |
+
app = FastAPI()
|
| 4 |
+
|
| 5 |
+
@app.get("/")
|
| 6 |
+
def greet_json():
|
| 7 |
+
return {"msg": "Hello, FastAPI Node World!"}
|
| 8 |
+
|
| 9 |
+
@app.get("/hello/")
|
| 10 |
+
def hello_json():
|
| 11 |
+
return {"msg": "/hello/ : Hello, FastAPI Node World!"}
|
| 12 |
+
|
| 13 |
+
# 带参数的路由
|
| 14 |
+
@app.route("/hi/<name>")
|
| 15 |
+
@app.route("/hi") # 兼容无参数情况
|
| 16 |
+
def hi_page(name=None):
|
| 17 |
+
if name is None:
|
| 18 |
+
name = "访客"
|
| 19 |
+
return f"<h1>你好,{name}!</h1><a href='/'>返回首页</a>"
|
scripts/start.sh
CHANGED
|
@@ -12,6 +12,6 @@ echo "Current Directory: $(pwd)"; echo "CPU Info:"; lscpu; echo "Disk Usage:"; d
|
|
| 12 |
nginx -c "$(pwd)/nginx/nginx.conf"
|
| 13 |
|
| 14 |
# 启动 FastAPI // --workers 3
|
| 15 |
-
uvicorn app:app --reload --host 127.0.0.1 --port 8000 --log-level info
|
| 16 |
|
| 17 |
echo "Server started ..."
|
|
|
|
| 12 |
nginx -c "$(pwd)/nginx/nginx.conf"
|
| 13 |
|
| 14 |
# 启动 FastAPI // --workers 3
|
| 15 |
+
uvicorn app:app --app-dir ./fastapi --reload --host 127.0.0.1 --port 8000 --log-level info
|
| 16 |
|
| 17 |
echo "Server started ..."
|