11from typing import Callable , Coroutine
22
3- try :
4- from asgiref .wsgi import WsgiToAsgi
5- from hypercorn .config import Config
6- from hypercorn .asyncio import serve
7- from flask import Flask , Blueprint
8- except ImportError as e :
9- raise ImportError ("Flask dependencies weren't installed. Please, install they with [flask] option" ) from e
3+ from flask import Flask , Blueprint
104
115from ..abc import BaseApi , BaseRouter
126
@@ -25,10 +19,9 @@ class FlaskAPI(BaseApi):
2519 def __init__ (self , host : str , port : int , ** kwargs ):
2620 self .host = host
2721 self .port = port
22+ self .debug = kwargs .pop ("debug" , False )
2823
2924 self .app : Flask = Flask (kwargs .pop ("import_name" , None ) or "interactions_restful" , ** kwargs )
30- self ._config = Config ()
31- self ._config .bind = [f"{ host } :{ port } " ]
3225
3326 def add_endpoint_method (self , coro : Callable [..., Coroutine ], endpoint : str , method : str , ** kwargs ):
3427 self .app .route (endpoint , methods = [method ], ** kwargs )(coro )
@@ -41,4 +34,4 @@ def add_router(self, router: FlaskRouter):
4134 self .app .register_blueprint (router .blueprint )
4235
4336 async def run (self ):
44- await serve ( WsgiToAsgi ( self .app ) , self ._config )
37+ self .app . run ( self . host , self .port , self . debug )
0 commit comments