Spaces:
Running
Running
Fix NameError: move SPACE_HOST definition before CORS configuration
Browse files- SPACE_HOST was being used before it was defined, causing NameError
- Moved OAuth and environment variables before CORS middleware
- This was breaking the sign-in and preventing the backend from starting
- backend_api.py +8 -8
backend_api.py
CHANGED
|
@@ -34,6 +34,13 @@ LANGUAGE_CHOICES = ["html", "gradio", "transformers.js", "streamlit", "comfyui",
|
|
| 34 |
|
| 35 |
app = FastAPI(title="AnyCoder API", version="1.0.0")
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
# Configure CORS - allow all origins in production, specific in dev
|
| 38 |
# In Docker Space, requests come from the same domain via Next.js proxy
|
| 39 |
ALLOWED_ORIGINS = os.getenv("ALLOWED_ORIGINS", "*").split(",") if os.getenv("ALLOWED_ORIGINS") else [
|
|
@@ -49,16 +56,9 @@ app.add_middleware(
|
|
| 49 |
allow_credentials=True,
|
| 50 |
allow_methods=["*"],
|
| 51 |
allow_headers=["*"],
|
| 52 |
-
allow_origin_regex=r"https://.*\.hf\.space" if
|
| 53 |
)
|
| 54 |
|
| 55 |
-
# OAuth configuration
|
| 56 |
-
OAUTH_CLIENT_ID = os.getenv("OAUTH_CLIENT_ID", "")
|
| 57 |
-
OAUTH_CLIENT_SECRET = os.getenv("OAUTH_CLIENT_SECRET", "")
|
| 58 |
-
OAUTH_SCOPES = os.getenv("OAUTH_SCOPES", "openid profile manage-repos")
|
| 59 |
-
OPENID_PROVIDER_URL = os.getenv("OPENID_PROVIDER_URL", "https://huggingface.co")
|
| 60 |
-
SPACE_HOST = os.getenv("SPACE_HOST", "localhost:7860")
|
| 61 |
-
|
| 62 |
# In-memory store for OAuth states (in production, use Redis or similar)
|
| 63 |
oauth_states = {}
|
| 64 |
|
|
|
|
| 34 |
|
| 35 |
app = FastAPI(title="AnyCoder API", version="1.0.0")
|
| 36 |
|
| 37 |
+
# OAuth and environment configuration (must be before CORS)
|
| 38 |
+
OAUTH_CLIENT_ID = os.getenv("OAUTH_CLIENT_ID", "")
|
| 39 |
+
OAUTH_CLIENT_SECRET = os.getenv("OAUTH_CLIENT_SECRET", "")
|
| 40 |
+
OAUTH_SCOPES = os.getenv("OAUTH_SCOPES", "openid profile manage-repos")
|
| 41 |
+
OPENID_PROVIDER_URL = os.getenv("OPENID_PROVIDER_URL", "https://huggingface.co")
|
| 42 |
+
SPACE_HOST = os.getenv("SPACE_HOST", "localhost:7860")
|
| 43 |
+
|
| 44 |
# Configure CORS - allow all origins in production, specific in dev
|
| 45 |
# In Docker Space, requests come from the same domain via Next.js proxy
|
| 46 |
ALLOWED_ORIGINS = os.getenv("ALLOWED_ORIGINS", "*").split(",") if os.getenv("ALLOWED_ORIGINS") else [
|
|
|
|
| 56 |
allow_credentials=True,
|
| 57 |
allow_methods=["*"],
|
| 58 |
allow_headers=["*"],
|
| 59 |
+
allow_origin_regex=r"https://.*\.hf\.space" if SPACE_HOST and not SPACE_HOST.startswith("localhost") else None,
|
| 60 |
)
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
# In-memory store for OAuth states (in production, use Redis or similar)
|
| 63 |
oauth_states = {}
|
| 64 |
|