from fastapi import FastAPI,Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi import File
from fastapi.responses import JSONResponse
import uvicorn
import json
app = FastAPI()
#将配置挂在到app上
app.add_middleware(
CORSMiddleware,
# 这里配置允许跨域访问的前端地址
allow_origins=["*"],
# 跨域请求是否支持 cookie, 如果这里配置true,则allow_origins不能配置*
allow_credentials=False,
# 支持跨域的请求类型,可以单独配置get、post等,也可以直接使用通配符*表示支持所有
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
async def index_get(request: Request):
"""
注册一个根路径
:return:
"""
try:
data= await request.json()
print("received data----",data)
except Exception as e:
print("request data error. ----",e)
return {"message": "Hello World"}
@app.post("/")
async def index():
"""
注册一个根路径
:return:
"""
return {"message": "Hello World"}
if __name__ == "__main__":
uvicorn.run(app="fastAPI_test_v212:app", host="0.0.0.0", reload=True, port=8020, workers=3)
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
miniprogram-1.zip (38个子文件)
fastAPI_simpleTest.py 1KB
wsServer.py 369B
miniprogram-1
project.private.config.json 371B
.eslintrc.js 587B
project.config.json 834B
miniprogram
sitemap.json 191B
pages
index
index.wxml 952B
index.json 27B
index.wxss 264B
index.ts 1KB
web-socket
web-socket.json 50B
web-socket.js 3KB
web-socket.wxml 1KB
web-socket.wxss 2B
request
request.js 1KB
request.json 52B
request.wxml 583B
request.wxss 0B
logs
logs.json 77B
logs.ts 362B
logs.wxml 197B
logs.wxss 106B
app.json 291B
utils
util.ts 474B
app.ts 385B
app.wxss 194B
package.json 256B
typings
index.d.ts 204B
types
index.d.ts 41B
wx
lib.wx.component.d.ts 32KB
lib.wx.api.d.ts 1.36MB
lib.wx.cloud.d.ts 30KB
lib.wx.behavior.d.ts 3KB
index.d.ts 7KB
lib.wx.page.d.ts 11KB
lib.wx.app.d.ts 16KB
lib.wx.event.d.ts 42KB
tsconfig.json 654B
共 38 条
- 1
资源评论
海里的鱼2022
- 粉丝: 8288
- 资源: 39
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功