Skip to content

Commit cdd432b

Browse files
committed
Refactoring
1 parent b0a273d commit cdd432b

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ APP__DEBUG=true
22
APP__PORT=8080
33
APP__URL=https://my.domain
44
APP__WEBHOOK_PATH=/webhook/tg
5+
APP__HEALTH_PATH=/healthz
6+
APP__WEB_APP_URL=https://my.domain/webapp
57
APP__DEFAULT_LANGUAGE=en
68

79
TG_BOT__TOKEN=

bot/configs/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class App(BaseSettings):
1010
url: str = 'https://my.domain'
1111
webhook_path: str = '/webhook/tg'
1212
health_path: str = '/healthz'
13+
web_app_url: str = 'https://my.domain/webapp'
1314
default_language: str = 'en'
14-
web_app_path: str = '/webapp'
1515

1616

1717
class TgBot(BaseSettings):

main.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,11 @@ def register_middlewares(dp: Dispatcher) -> None:
105105

106106

107107
def register_workflow_data(dp: Dispatcher, lexicon: Lexicon, app_settings: App) -> None:
108-
base_url = app_settings.url.rstrip('/')
109-
web_app_path = '/' + app_settings.web_app_path.lstrip('/')
110108
dp.workflow_data.update({
111109
'lexicon': lexicon,
112110
'keyboards': Keyboards(),
113111
'bot_service': BotService(),
114-
'web_app_url': f'{base_url}{web_app_path}',
112+
'web_app_url': app_settings.web_app_url,
115113
})
116114

117115

@@ -120,9 +118,9 @@ def create_app(bot: Bot, dp: Dispatcher, settings: App) -> FastAPI:
120118
app.add_event_handler('startup', create_startup_handler(bot, dp, settings.url + settings.webhook_path))
121119
app.add_event_handler('shutdown', create_shutdown_handler(bot, settings.debug))
122120
app.add_api_route(settings.webhook_path, create_webhook_handler(bot, dp), methods=['POST'])
123-
app.add_api_route(settings.health_path, lambda: {"status": "ok"}, methods=["GET"])
121+
app.add_api_route(settings.health_path, lambda: {'status': 'ok'}, methods=['GET'])
124122
web_app_dir = Path(__file__).resolve().parent / 'webapp'
125-
app.mount(settings.web_app_path, StaticFiles(directory=web_app_dir, html=True), name='webapp')
123+
app.mount('/webapp', StaticFiles(directory=web_app_dir, html=True), name='webapp')
126124

127125
return app
128126

0 commit comments

Comments
 (0)