Giter Club home page Giter Club logo

Comments (5)

bitrate16 avatar bitrate16 commented on September 25, 2024

Could you please give an example of what does CORS for dynamic route means? I'm not very familiar with CORS

from aiohttp-dynamic.

ashish-jabble avatar ashish-jabble commented on September 25, 2024

@bitrate16 I have used aiohttp dynamic routes to my application on-fly. And to consume those routes I have a Angular based GUI client to access these. Therefore we need to setup CORS to the dynamic routes so that Preflight request (OPTIONS) that is sent by the browser before the actual request should handle.

Here is the usage of Cross Origin Resource Sharing (CORS) https://github.com/aio-libs/aiohttp-cors#usage

This is I have used for the old routes in my application

def enable_cors(app):
    """ implements Cross Origin Resource Sharing (CORS) support """
    import aiohttp_cors
    # Configure default CORS settings.
    cors = aiohttp_cors.setup(app, defaults={
        "*": aiohttp_cors.ResourceOptions(
            allow_methods=["GET", "POST", "PUT", "DELETE"],
            allow_credentials=True,
            expose_headers="*",
            allow_headers="*",
        )
    })
    # Configure CORS on all routes.
    for route in list(app.router.routes()):
        cors.add(route)

Now I want to use the same CORS for dynamic routes.

from aiohttp-dynamic.

bitrate16 avatar bitrate16 commented on September 25, 2024

@ashish-jabble
In case when you don't need route-specific CORS for your webapp (for example when you want to ALLOW_ALL or use same rules for all paths) you may use aiohttp-middlewares as middleware.

For example:

import aiohttp_middlewares

app = aiohttp.web.Application(middlewares=[
	aiohttp_middlewares.cors_middleware(allow_all=True), # CORS pass
)

This will act as middleware for all handlers, including dynamic.

In other case I will look how to implement it later.

from aiohttp-dynamic.

ashish-jabble avatar ashish-jabble commented on September 25, 2024

@bitrate16 Above will only work with Python3.7+.
My Project has minimum Python 3.6 supported so it does not fit to my requirement. Also I am avoiding to add new dependency unless no possibilities with existing.
FYI, Below are the aiohttp Pip packages I have used so far

aiohttp==3.8.1
aiohttp_cors==0.7.0
aiohttp-dynamic==1.3.0

Is there any possibility to achieve CORS support with your aiohttp-dynamic?

Thanks in advance!

from aiohttp-dynamic.

bitrate16 avatar bitrate16 commented on September 25, 2024

For now I don't know the best way of implementing this cross-library support because my extension operates using different route representation (dict vs wrapper object) and this would require rewriting this part of the code that is not possible for me now due to the lack of time.

from aiohttp-dynamic.

Related Issues (1)

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.