Code Monkey home page Code Monkey logo

Comments (13)

rutsky avatar rutsky commented on September 2, 2024

@trivigy thank you for posting this bug report and sorry for the long delay.

Yes, as I see * handler from class based view's (CBV) takes precedence over OPTIONS handler being added by aiohttp-cors, and I don't see easy way to handle CBV classes in aiohttp-cors so currently it will not work with them.

Perhaps best solution will be to introduce aiohttp-cors mixin for CBV which will handle OPTIONS and require users to inherit from it, like:

# Not implemented yet
from aiohttp_cors import ViewMixin

class MyView(ViewMixin, web.View):
    async def get(self):
        return await get_resp(self.request)

    async def post(self):
        return await post_resp(self.request)

from aiohttp-cors.

asvetlov avatar asvetlov commented on September 2, 2024

Makes sense

from aiohttp-cors.

balloob avatar balloob commented on September 2, 2024

I am using the following workaround to register my classes so that they work with aiohttp_cors:

def register_view(app, url, view):
    for method in ('get', 'post', 'delete', 'put'):
        handler = getattr(view, method, None)

        if not handler:
            continue

        app.router.add_route(method, url, handler)

from aiohttp-cors.

rutsky avatar rutsky commented on September 2, 2024

@balloob will aiohttp_cors.ViewMixin mixin will help you if it will be implemented in aiohttp_cors?

from aiohttp-cors.

balloob avatar balloob commented on September 2, 2024

Probably - but I was already using views in a weird way: I wanted to instantiate the views before registering them so I could keep a reference to the state of the house (I'm working on Home Assistant). So I actually had a __call__ method on my instantiated view that would handle the routing to get/post etc. (I know that it's not the right way but we're transitioning from CherryPi WSGI server + Werkzeug and getting it to work is the first step.)

from aiohttp-cors.

asvetlov avatar asvetlov commented on September 2, 2024

@balloob if you want to instantiate your view classes before registering you don't need aiohttp.web.View at all -- custom classes may serve everything perfectly.

from aiohttp-cors.

trivigy avatar trivigy commented on September 2, 2024

@rutsky Thanks for the suggestion. Took me a long time to notice that you responded. I actually use a very custom implementation of the View within our system. I personally wanted to add a whole lot more functionalities to the view and therefore re-implemented it. Had to override add_route() functions and all. Therefore this problem was never an issue for my systems but it was certainly a bug worth reporting.

from aiohttp-cors.

buhman avatar buhman commented on September 2, 2024

@balloob's hack works ok for me as well, but I think a ViewMixin would be better.

from aiohttp-cors.

asvetlov avatar asvetlov commented on September 2, 2024

Guys, we need a champion for the issue.
Do anybody want work on PR?

from aiohttp-cors.

rutsky avatar rutsky commented on September 2, 2024

I recently changed job, moved to another country and on paternity leave right now, so I don't have free time right now, sorry.

from aiohttp-cors.

pedrokiefer avatar pedrokiefer commented on September 2, 2024

@asvetlov @rutsky would you please review my PR?

from aiohttp-cors.

asvetlov avatar asvetlov commented on September 2, 2024

Let me setup coverage tools first, I'll return to review after that.

from aiohttp-cors.

pedrokiefer avatar pedrokiefer commented on September 2, 2024

👍 💯

from aiohttp-cors.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.