diff --git a/app/__main__.py b/app/__main__.py index f919445..b9b8549 100644 --- a/app/__main__.py +++ b/app/__main__.py @@ -5,6 +5,7 @@ from datetime import datetime import asyncio, sys from aiogram import Bot +import time from app.api import app from app.bot import dp @@ -78,6 +79,8 @@ if __name__ == '__main__': app.run(host='0.0.0.0', port=SANIC_PORT) else: + time.sleep(3) + startup_fn = None if startup_target == 'indexator': from app.core.background.indexator_service import main as target_fn diff --git a/app/api/__init__.py b/app/api/__init__.py index 3f95175..e70885d 100644 --- a/app/api/__init__.py +++ b/app/api/__init__.py @@ -10,7 +10,7 @@ from app.api.middleware import attach_user_to_request, close_db_session, close_r app.register_middleware(attach_user_to_request, "request") app.register_middleware(close_db_session, "response") -from app.api.routes._index import s_index +from app.api.routes._index import s_index, s_favicon from app.api.routes._system import s_api_system, s_api_system_version, s_api_system_send_status from app.api.routes.auth import s_api_v1_auth_twa from app.api.routes.statics import s_api_tonconnect_manifest, s_api_platform_metadata @@ -19,7 +19,8 @@ from app.api.routes.account import s_api_v1_account_get from app.api.routes._blockchain import s_api_v1_blockchain_send_new_content_message, \ s_api_v1_blockchain_send_purchase_content_message -app.add_route(s_index, "/") +app.add_route(s_index, "/", methods=["GET", "OPTIONS"]) +app.add_route(s_favicon, "/favicon.ico", methods=["GET", "OPTIONS"]) app.add_route(s_api_system, "/api/node", methods=["GET", "OPTIONS"]) app.add_route(s_api_system_version, "/api/system.version", methods=["GET", "OPTIONS"]) diff --git a/app/api/routes/_index.py b/app/api/routes/_index.py index a36b6dc..0245548 100644 --- a/app/api/routes/_index.py +++ b/app/api/routes/_index.py @@ -2,5 +2,14 @@ from sanic import response async def s_index(request): - return response.text("OK") + return response.json({ + 'success': True, + 'message': 'Welcome to the @MY API!' + }) + + +async def s_favicon(request): + return response.redirect( + "https://git.projscale.dev/my-dev/assets/raw/commit/81de5356c6b1d6f01988d77e22c580114b32bcbd/images/logo.jpg" + ) diff --git a/app/api/routes/_system.py b/app/api/routes/_system.py index 09ec911..5515ef0 100644 --- a/app/api/routes/_system.py +++ b/app/api/routes/_system.py @@ -3,6 +3,7 @@ from base58 import b58encode, b58decode from app.core._secrets import hot_pubkey, service_wallet, hot_privkey from app.core._blockchain.ton.platform import platform from datetime import datetime, timedelta +from app.core.logger import make_log from app.core._crypto.signer import Signer import subprocess import json @@ -51,7 +52,7 @@ async def s_api_system_send_status(request): 'status': message['status'], 'timestamp': datetime.now(), } - + make_log("Health", f"Service {message['service']} status: {message['status']}", level='info') return response.json({'message': 'Status received'}) diff --git a/app/core/_utils/send_status.py b/app/core/_utils/send_status.py index aefcfac..0ceb33f 100644 --- a/app/core/_utils/send_status.py +++ b/app/core/_utils/send_status.py @@ -9,21 +9,23 @@ from app.core._crypto.signer import Signer async def send_status(service: str, status: str): - message = { - 'service': service, - 'status': status, - } - message_bytes = dumps(message).encode() - signer = Signer(hot_seed) - message_signature = signer.sign(message_bytes) - async with AsyncClient() as client: - res = await client.post( - f"{PROJECT_HOST}/api/system.sendStatus", - json={ - 'message': b58encode(message_bytes).decode(), - 'signature': message_signature, - } - ) - if res.status_code != 200: - make_log("send_status", f"Error (service={service}, status={status}, response={res.text})", level='error') - + try: + message = { + 'service': service, + 'status': status, + } + message_bytes = dumps(message).encode() + signer = Signer(hot_seed) + message_signature = signer.sign(message_bytes) + async with AsyncClient() as client: + res = await client.post( + f"{PROJECT_HOST}/api/system.sendStatus", + json={ + 'message': b58encode(message_bytes).decode(), + 'signature': message_signature, + } + ) + if res.status_code != 200: + make_log("send_status", f"Error (service={service}, status={status}, response={res.text})", level='error') + except BaseException as e: + make_log("send_status", f"Error: {e}", level='error')