فهرست منبع

Fix: “--api-key” argument in api_server.py does not work (#910)

* Fix: By api_auth middleware not being used,
Fixed a problem in which --api_key did not work due to api_auth not being used.

- Implement API authentication middleware
- Add OpenAPI configuration
- Modify route handling to support middleware injection

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
inovue 1 سال پیش
والد
کامیت
cddfd4dd5b
1فایلهای تغییر یافته به همراه6 افزوده شده و 1 حذف شده
  1. 6 1
      tools/api_server.py

+ 6 - 1
tools/api_server.py

@@ -29,7 +29,6 @@ from tools.server.views import routes
 class API(ExceptionHandler):
     def __init__(self):
         self.args = parse_args()
-        self.routes = routes
 
         def api_auth(endpoint):
             async def verify(token: Annotated[str, Depends(bearer_auth)]):
@@ -45,6 +44,12 @@ class API(ExceptionHandler):
             else:
                 return passthrough
 
+        self.routes = Routes(
+            routes,  # keep existing routes
+            http_middlewares=[api_auth],  # apply api_auth middleware
+        )
+
+        # OpenAPIの設定
         self.openapi = OpenAPI(
             Info(
                 {