From 8c49505cf6c5d54782c9278df0794fe0eb91d97d Mon Sep 17 00:00:00 2001 From: wupasscat Date: Thu, 20 Apr 2023 21:25:02 -0400 Subject: [PATCH 1/3] use redis json --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index a9d8033..dfcfe33 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ import os -import redis.asyncio as redis +import redis import uvicorn from fastapi import Depends, FastAPI from fastapi.middleware.cors import CORSMiddleware @@ -53,7 +53,7 @@ def read_root(): def read_world(world_id: int, cache = Depends(get_redis)): for i in WORLD_IDS: if WORLD_IDS[i] == world_id: - world_data = cache.hgetall(i) + world_data = cache.json().get(i) return world_data From 442b3849e4169bc4d8004aec8e15803bff27b2cb Mon Sep 17 00:00:00 2001 From: wupasscat Date: Tue, 25 Apr 2023 17:48:00 -0400 Subject: [PATCH 2/3] use query parameters --- main.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index dfcfe33..e184d87 100644 --- a/main.py +++ b/main.py @@ -33,12 +33,14 @@ def get_redis(): app = FastAPI() origins = [ - BASE_URL + BASE_URL, + '127.0.0.1' ] app.add_middleware( CORSMiddleware, - allow_origins=origins, + # allow_origins=origins, + allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], @@ -49,10 +51,10 @@ def get_redis(): def read_root(): return {"Hello": "World"} -@app.get("/worlds/{world_id}") -def read_world(world_id: int, cache = Depends(get_redis)): +@app.get("/worlds/") +def read_world(id: int, cache = Depends(get_redis)): for i in WORLD_IDS: - if WORLD_IDS[i] == world_id: + if WORLD_IDS[i] == id: world_data = cache.json().get(i) return world_data From d1526c3edab54ada04cb96be8eb5bcd3d3ded0f1 Mon Sep 17 00:00:00 2001 From: wupasscat Date: Tue, 25 Apr 2023 22:39:52 -0400 Subject: [PATCH 3/3] add metadata --- main.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index e184d87..6093acb 100644 --- a/main.py +++ b/main.py @@ -13,8 +13,9 @@ load_dotenv() -BASE_URL = os.getenv('BASE_URL') or '0.0.0.0' +BASE_URL = os.getenv('BASE_URL') or None LOG_LEVEL = os.getenv('LOG_LEVEL') or 'INFO' +VERSION = os.getenv('VERSION') or '1.0.0' WORLD_IDS = { 'connery': 1, @@ -30,7 +31,15 @@ def get_redis(): return redis.Redis(connection_pool=pool) -app = FastAPI() +app = FastAPI( + title = "Warpgate API", + version = VERSION, + license_info = { + "name": "GNU General Public License v3.0", + "url": "https://www.gnu.org/licenses/gpl-3.0.html" + }, + root_path = BASE_URL +) origins = [ BASE_URL,