""" sanic server """ from app import app from cloudant import Cloudant from views.routers import blueprint app.blueprint(blueprint) @app.listener('before_server_start') def start_connection(app, loop): app.client = Cloudant(app.config.COUCHDB_USER, app.config.COUCHDB_PASSWORD, url=app.config.COUCHDB_URL, connect=True) app.db = app.client[app.config.COUCHDB_DATABASE] app.records = app.client[app.config.COUCHDB_RECORDS] @app.listener('after_server_stop') def stop_connection(app, loop): app.client.disconnect() def run_server(): """启动服务器 根据启动参数加载配置, 如果没有相应的配置文件直接抛出错误 """ app.run(host=app.config.HOST,
from app import app from blueprints import articles_bp app.blueprint(articles_bp) if __name__ == '__main__': app.run(host='0.0.0.0', port='9000')
""" sanic server """ from app import app from app import listeners from views.routers import api_blueprint, admin_blueprint, k8s_blueprint app.listener('before_server_start')(listeners.setup_db_session) app.listener('before_server_start')(listeners.setup_sentry_client) app.listener('after_server_stop')(listeners.teardown_connection) app.blueprint(api_blueprint) app.blueprint(admin_blueprint) app.blueprint(k8s_blueprint) def run_server(): """启动服务器 根据启动参数加载配置, 如果没有相应的配置文件直接抛出错误 """ app.run( host=app.config.HOST, port=app.config.PORT, workers=app.config.WORKERS, debug=app.config.DEBUG)
limitations under the License. """ from app import app from app.cache import mem_cache from app.service.eventloop import do from indy.error import IndyError from von_agent.error import VonAgentError from sanic import response from sanic_openapi import doc, openapi_blueprint, swagger_blueprint import json import logging logger = logging.getLogger(__name__) app.blueprint(openapi_blueprint) app.blueprint(swagger_blueprint) app.config.API_VERSION = '1.0.0' app.config.API_TITLE = 'von_conx' app.config.API_TERMS_OF_SERVICE = 'For demonstration of von_agent API' app.config.API_PRODUCES_CONTENT_TYPES = ['application/json'] app.config.API_CONTACT_EMAIL = '*****@*****.**' @app.get('/api/v0/did') @doc.summary("Returns the agent's JSON-encoded DID") @doc.produces(str) async def did(request): logger.debug('Processing GET {}'.format(request.url)) ag = await mem_cache.get('agent') rv_json = await ag.process_get_did()
from sanic.response import HTTPResponse from app import app from api.blueprints import content @app.route('/') async def handler(request): return HTTPResponse(status=200, body='Welcome to Sanic!') app.blueprint(content)
from app import app from app.mqtt.broker import start_broker from app.mqtt.subscribe import start_sub from threading import Thread import asyncio from app.views import login from app.views.index import bp_index app.static('/static', './app/static') app.blueprint(bp_index) if __name__ == "__main__": Thread(target=start_broker).start() Thread(target=start_sub).start() app.run(host="0.0.0.0", port=21025, debug=False)
""" sanic server """ from app import app from app import middleware from views.views import api_blueprint from libs.generics import handle_exception app.middleware('request')(middleware.authenticate) app.blueprint(api_blueprint) @app.exception(Exception) async def handle_dispatch_exception(request, exception): return (await handle_exception(exception)) def run_server(): """启动服务器 根据启动参数加载配置, 如果没有相应的配置文件直接抛出错误 """ app.run(host=app.config.HOST, port=app.config.PORT, workers=app.config.WORKERS, debug=app.config.DEBUG)