CJYen 3 years ago
parent
commit
e904150724
2 changed files with 44 additions and 13 deletions
  1. 31 0
      call.py
  2. 13 13
      main.py

+ 31 - 0
call.py

@@ -0,0 +1,31 @@
+import uvicorn
+import fastapi
+from fastapi.middleware.cors import CORSMiddleware
+import models
+
+app = fastapi.FastAPI()
+
+app.add_middleware(
+    CORSMiddleware,
+    allow_origins=['*'],
+    allow_credentials=True,
+    allow_methods=["*"],
+    allow_headers=["*"],
+)
+
+@app.post("/callevent")
+async def callevent(userModel: models.callBack):
+    """
+    事件會用application/json和POST方式打到指定位址, 內容基本包含
+    {
+      "type": "xxx", // 事件類型, 字串
+      "data": {} // 事件內容資料
+    }
+    """
+    str1 =  userModel.type
+    dict1 = userModel.data
+    result = str1, dict1
+    return result
+
+if __name__ == '__main__':
+    uvicorn.run("call:app", host="0.0.0.0", port=5000, reload=True)

+ 13 - 13
main.py

@@ -262,19 +262,19 @@ async def buy(userModel : models.BuyNft):
         db.close()
     return "您已購買成功!"
 
-@app.post("/callevent")
-async def callevent(userModel: models.callBack):
-    """
-    事件會用application/json和POST方式打到指定位址, 內容基本包含
-    {
-      "type": "xxx", // 事件類型, 字串
-      "data": {} // 事件內容資料
-    }
-    """
-    str1 =  userModel.type
-    dict1 = userModel.data
-    result = str1, dict1
-    return result
+# @app.post("/callevent")
+# async def callevent(userModel: models.callBack):
+#     """
+#     事件會用application/json和POST方式打到指定位址, 內容基本包含
+#     {
+#       "type": "xxx", // 事件類型, 字串
+#       "data": {} // 事件內容資料
+#     }
+#     """
+#     str1 =  userModel.type
+#     dict1 = userModel.data
+#     result = str1, dict1
+#     return result
 
 if __name__ == '__main__':
     uvicorn.run("main:app", host="0.0.0.0", port=8228, reload=True,ssl_context=('/etc/letsencrypt/live/ark.cards/fullchain.pem', '/etc/letsencrypt/live/ark.cards/privkey.pem'))