12
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
from order_api import Order
|
||||
from product_api import Product
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from midlleware import m1,m2
|
||||
app = FastAPI()
|
||||
|
||||
app.include_router(Order)
|
||||
app.include_router(Product)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=['*'],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
|
||||
app.middleware('http')(m1)
|
||||
app.middleware('https')(m2)
|
||||
@@ -0,0 +1,17 @@
|
||||
from fastapi import Response
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
async def m1(req,next):
|
||||
if req.client.host in ['192.168.5.14','192.168.5.17','127.0.0.1']:
|
||||
return Response(content='gun')
|
||||
r=await next(req)
|
||||
return r
|
||||
|
||||
|
||||
async def m2(req,next):
|
||||
a=datetime.now()
|
||||
r=await next(req)
|
||||
b=datetime.now()
|
||||
print(b-a)
|
||||
return r
|
||||
@@ -0,0 +1,9 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
Order = APIRouter()
|
||||
@Order.get("/dindan")
|
||||
def dindan():
|
||||
return "dindan"
|
||||
@Order.post("/dindan")
|
||||
def dindan():
|
||||
return "dindan"
|
||||
@@ -0,0 +1,9 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
Product=APIRouter()
|
||||
@Product.get("/shanping")
|
||||
def shaning():
|
||||
return {"message":"Hello World"}
|
||||
@Product.post("/shaning")
|
||||
def shaning():
|
||||
return {"message":"Hello World"}
|
||||
Reference in New Issue
Block a user