Comments (5)
Could you please give an example of what does CORS for dynamic route means? I'm not very familiar with CORS
from aiohttp-dynamic.
@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.
@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.
@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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiohttp-dynamic.