from rocinante import Rocinante from flask import Flask app = Rocinante() flask_app = Flask(__name__) @flask_app.route('/index') def flask_test(): return 'flask_index!' app.mount_wsgi_app(flask_app, path='/flask') if __name__ == '__main__': app.run('0.0.0.0', 8000)
def __init__(self, application: Rocinante): # get config from app mysql_config = application.get_config('mysql') self.mysql_pool = MySQLConnectionPool(**mysql_config)
from rocinante import Rocinante, RequestHandler from mysql.connector.pooling import MySQLConnectionPool app = Rocinante() # config class class MySQLConfig(object): pool_size = 2 host = '127.0.0.1' port = 3306 database = 'Rocinante' user = '******' password = '******' pool_reset_session = True # load config to app app.load_config('mysql', MySQLConfig) class MySQLMixin(object): def __init__(self, application: Rocinante): # get config from app mysql_config = application.get_config('mysql') self.mysql_pool = MySQLConnectionPool(**mysql_config) class MySQLHandler(RequestHandler, MySQLMixin): def get(self):
from rocinante import Rocinante, Request app = Rocinante() @app.route('/') def hello(request: Request): return 'hello world!' if __name__ == '__main__': app.run('0.0.0.0', 8000)
from rocinante import Rocinante from rocinante.middleware import CORSMiddleware app = Rocinante() app.add_middleware(CORSMiddleware) if __name__ == '__main__': app.run('0.0.0.0', 8000)
from rocinante import Rocinante, RequestHandler, Router, Request, Url app = Rocinante() # other way to register handler class HelloHandler(RequestHandler): def get(self): print(self.url) return 'get!' def post(self): print(self.url) return 'post!' app.add_handler('/', HelloHandler) # user router router = Router() # different way to register handler # 1 """""" @router.route('/test', methods=['GET', 'POST']) def router_handler(request: Request): if request.method == 'GET': return 'get!'