def create_app(): """ Create basic application, define API endpoints :return: web app """ ws = WebSockets(log) csrf_policy = aiohttp_csrf.policy.FormPolicy(CSRFCongiruation.FORM_FIELD_NAME) csrf_storage = aiohttp_csrf.storage.CookieStorage(CSRFCongiruation.COOKIE_NAME) app = Application(middlewares=[auth_middleware]) app.add_routes( routes=[ # Render web.get("/register", Register.get), web.get("/login", Login.get), web.get("/chat", Chat.get), web.get("/", Home.get), # Api web.post("/api/register", Register.post), web.post("/api/login", Login.post), web.post("/api/logout", Logout.post), web.get("/api/chat/ws", ws.get), web.get("/api/health", HealthCheck.get), # Static web.static("/static/js", path=DefaultPaths.STATIC_JS, append_version=True), # Feedback web.view("/feedback", Feedback), ] ) aiohttp_csrf.setup(app, policy=csrf_policy, storage=csrf_storage) app.middlewares.append(csrf) return app
def run_website(bot: RoleplayBot): app = Application() app['bot'] = bot aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader(TEMPLATES_PATH), context_processors=[global_variables]) app.add_routes(routes) app.add_routes([web.static('/', STATIC_PATH)]) return _run_app(app, host='0.0.0.0', port=8081)
def build_routes(app: Application): app.add_routes([ web.get('/', root_handler), web.get('/groups', group_list_handler), web.get('/vehicles', vehicle_list_handler), web.get(r'/vehicles/{vehicle_id:\d+}', vehicle_item_handler), web.get(r'/vehicles/{vehicle_id:\d+}/configuration', vehicle_configuration_handler), ])
def bind(self, app: Application) -> None: app.add_routes( [ web.post("/conversation/{character_id}", self.main_page), web.post("/conversation/{character_id}/start", self.start), web.post("/conversation/{character_id}/read/{conversation_id}", self.read), web.post("/conversation/{character_id}/add/{conversation_id}", self.add), ] )
def init_routes(app: Application) -> None: app.add_routes([ web.get("/", version_api), web.post("/", version_api), web.post("/create", create_api), web.post("/read", read_api), web.get("/read", read_api), web.post("/update", update_api), web.post("/delete", delete_api), ])
def bind(self, app: Application) -> None: app.add_routes([ web.get("/zones/tiles", self.get_tiles), web.get("/zones/{row_i}/{col_i}", self.get_zone), web.get("/zones/{row_i}/{col_i}/events", self.events), web.get("/zones/{row_i}/{col_i}/characters", self.get_characters), web.get("/zones/{row_i}/{col_i}/stuff", self.get_stuff), web.get("/zones/{row_i}/{col_i}/resources", self.get_resources), web.get("/zones/{row_i}/{col_i}/builds", self.get_builds), web.post("/zones/{row_i}/{col_i}/describe/{character_id}", self.describe), web.post("/zones/{row_i}/{col_i}/messages", self.messages), web.post("/zones/{row_i}/{col_i}/messages/add", self.add_message), ])
def add_routes(app: Application) -> None: """ Register routes and cors :param app: aiohttp app """ ping: Ping = Ping() opening_hours: OpeningHours = OpeningHours() app.add_routes([ # GET handlers web.get(f"/{APP_VERSION}/", ping.get), web.get(f"/{APP_VERSION}/opening_hours", opening_hours.get), # POST Handlers web.post(f"/{APP_VERSION}/opening_hours", opening_hours.post), ])
async def create_application() -> Application: """Создание WEB приложения.""" application = Application() application['database_settings'] = database_settings application['settings'] = application_settings cors_options = aiohttp_cors.ResourceOptions(expose_headers='*', allow_headers='*') aiohttp_cors.setup(application, defaults={'*': cors_options}) application.add_routes(views.routes) setup_middlewares(application) application.on_startup.append(init_mysql) application.on_cleanup.append(close_mysql) application.on_startup.append(init_redis) application.on_cleanup.append(close_redis) application.on_startup.append(_create_logs_file) return application
def bind(self, app: Application) -> None: url_base = "/affinity/{character_id}" app.add_routes([ web.post(url_base, self.main_page), web.post(url_base + "/new", self.new), web.post(url_base + "/list", self.list), web.post(url_base + "/see/{affinity_id}", self.see), web.post(url_base + "/edit-relation/{affinity_id}", self.edit_relation), web.post(url_base + "/manage/{affinity_id}", self.manage), web.post(url_base + "/manage-requests/{affinity_id}", self.manage_requests), web.post(url_base + "/manage-relations/{affinity_id}", self.manage_relations), web.post( url_base + "/manage-relations/{affinity_id}/{relation_character_id}", self.manage_relation, ), ])
def bind(self, app: Application) -> None: app.add_routes([ web.post("/business/{character_id}", self.main_page), web.post("/business/{character_id}/offers", self.offers), web.post("/business/{character_id}/offers-create", self.create), web.post("/business/{character_id}/offers/{offer_id}", self.offer), web.post( "/business/{character_id}/see-offer/{owner_id}/{offer_id}", self.see), web.post( "/business/{character_id}/see-offer/{owner_id}/{offer_id}/deal", self.deal), web.post("/business/{character_id}/offers/{offer_id}/add-item", self.add_item), web.post( "/business/{character_id}/offers/{offer_id}/remove-item/{item_id}", self.remove_item, ), web.post("/business/{character_id}/transactions", self.transactions), # web.post("/business/{character_id}/transactions/{offer_id}", self.transaction), ])
def bind(self, app: Application) -> None: app.add_routes([web.get("/world/source", self.get_world_source)])
def bind(self, app: Application) -> None: app.add_routes([web.post(DESCRIBE_BUILD, self._describe)])
def bind(self, app: Application) -> None: app.add_routes([web.get("/image/{image_id:\d+}", self.get_image)])
def setup_routes(app: Application): app.add_routes([ web.get('/posts', list_posts), ])