CORS plugin for Bottle framework
Project description
# bottle-cors
Simple plugin to easily enable [CORS](https://www.moesif.com/blog/technical/cors/Authoritative-Guide-to-CORS-Cross-Origin-Resource-Sharing-for-REST-APIs/)
support in [Bottle](https://bottlepy.org/) routes.
### Example
```python
from bottle import Bottle, request, run
from truckpad.bottle.cors import CorsPlugin, enable_cors
app = Bottle()
@app.get('/')
def index():
"""
CORS is disabled for this route
"""
return "cors is disabled here"
@enable_cors
@app.get('/endpoint_1')
def endpoint_1():
"""
CORS is enabled for this route.
OPTIONS requests will be handled by the plugin itself
"""
return "cors is enabled, OPTIONS handled by plugin"
@enable_cors
@app.route('/endpoint_2', method=['GET', 'POST', 'OPTIONS'])
def endpoint_2():
"""
CORS is enabled for this route.
OPTIONS requests will be handled by *you*
"""
if request.method == 'OPTIONS':
# do something here?
pass
return "cors is enabled, OPTIONS handled by you!"
app.install(CorsPlugin(origins=['http://list.of.allowed.domains.com', 'https://another.domain.org']))
run(app)
```
Simple plugin to easily enable [CORS](https://www.moesif.com/blog/technical/cors/Authoritative-Guide-to-CORS-Cross-Origin-Resource-Sharing-for-REST-APIs/)
support in [Bottle](https://bottlepy.org/) routes.
### Example
```python
from bottle import Bottle, request, run
from truckpad.bottle.cors import CorsPlugin, enable_cors
app = Bottle()
@app.get('/')
def index():
"""
CORS is disabled for this route
"""
return "cors is disabled here"
@enable_cors
@app.get('/endpoint_1')
def endpoint_1():
"""
CORS is enabled for this route.
OPTIONS requests will be handled by the plugin itself
"""
return "cors is enabled, OPTIONS handled by plugin"
@enable_cors
@app.route('/endpoint_2', method=['GET', 'POST', 'OPTIONS'])
def endpoint_2():
"""
CORS is enabled for this route.
OPTIONS requests will be handled by *you*
"""
if request.method == 'OPTIONS':
# do something here?
pass
return "cors is enabled, OPTIONS handled by you!"
app.install(CorsPlugin(origins=['http://list.of.allowed.domains.com', 'https://another.domain.org']))
run(app)
```
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for bottle_cors-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d27e89fcd4be3209b083cd7065af48ed4eb9eb2171006de601f358323e141bfa |
|
MD5 | f40ad7cc6ed3933c91db338740cdd29f |
|
BLAKE2b-256 | f309b19eb3293bebfe02dff8f5480d0401779f71e5da39a2b39dbf76668daaab |