def serve(reload=False): """Run a web server (for development only).""" # Debug only. static(app, "/explorer/", Path(__file__).parent / "explorer") if reload: hupper.start_reloader("trefle.bin.serve") traceback(app) simple_server(app)
def serve(reload=False): """Run a web server (for development only).""" if reload: import hupper hupper.start_reloader("copanier.serve") static(app, root=Path(__file__).parent / "static") simple_server(app, port=2244)
def serve(reload=False): """Run a web server (for development only).""" from roll.extensions import simple_server from .views import app if reload: import hupper hupper.start_reloader("egapro.bin.serve") simple_server(app, port=2626)
import asyncio import os import uvloop from aiofile import AIOFile, Reader from roll import Roll from roll.extensions import cors, igniter, logger, simple_server, traceback asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) app = Roll() cors(app) logger(app) traceback(app) @app.route("/fullasync", methods=["POST"], lazy_body=True) async def fullasync(request, response): response.body = (chunk async for chunk in request) if __name__ == "__main__": simple_server(app)
message += f" [envoyé depuis {parse(user_agent)}]" if request.host.startswith("127.0.0.1"): print(message) else: await request.app.bot.send_message(message) response.status = HTTPStatus.ACCEPTED response.json = {"message": message} @app.listen("error") async def json_error_response(request, response, error): if isinstance(error.message, str): error.message = {"error": error.message} elif isinstance(error.message, bytes): error.message = {"error": error.message.decode("utf-8")} response.json = error.message if error.status != HTTPStatus.NOT_FOUND: logger.debug( f"HttpError: status={error.status}, message={response.body}, " f"request={request.body.decode('utf-8')}, " f"url={request.url.decode('utf-8')}") if __name__ == "__main__": logging.basicConfig(level=logging.DEBUG) simple_server(app, host=os.environ.get("HOST", "127.0.0.1"), port=os.environ.get("PORT", 5678))
def run() -> None: simple_server(app)