Spaces:
Running
on
Zero
Running
on
Zero
dfa
Browse files- mysite/asgi.py +16 -9
mysite/asgi.py
CHANGED
@@ -58,15 +58,22 @@ app.add_middleware(
|
|
58 |
|
59 |
# 認証用ミドルウェア
|
60 |
|
61 |
-
@app.
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
# Gradioインターフェースの設定
|
72 |
gradio_interfaces = setup_gradio_interfaces()
|
|
|
58 |
|
59 |
# 認証用ミドルウェア
|
60 |
|
61 |
+
@app.get("/")
|
62 |
+
def read_root(credentials: HTTPBasicCredentials = Depends(authenticate)):
|
63 |
+
return {"message": f"Hello, {credentials.username}"}
|
64 |
+
|
65 |
+
# ミドルウェアで認証を追加
|
66 |
+
class BasicAuthMiddleware(BaseHTTPMiddleware):
|
67 |
+
async def dispatch(self, request, call_next):
|
68 |
+
credentials = security(request)
|
69 |
+
try:
|
70 |
+
authenticate(credentials)
|
71 |
+
except HTTPException as exc:
|
72 |
+
return JSONResponse(status_code=exc.status_code, content={"detail": exc.detail})
|
73 |
+
response = await call_next(request)
|
74 |
+
return response
|
75 |
+
|
76 |
+
app.add_middleware(BasicAuthMiddleware)
|
77 |
|
78 |
# Gradioインターフェースの設定
|
79 |
gradio_interfaces = setup_gradio_interfaces()
|