Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand All @@ -30,15 +31,25 @@ 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
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=["*"],
Expand All @@ -49,11 +60,11 @@ 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:
world_data = cache.hgetall(i)
if WORLD_IDS[i] == id:
world_data = cache.json().get(i)
return world_data


Expand Down