hug CORS middleware
A hug middleware for allowing CORS (cross-origin resource sharing) requests from hug servers.
Installation
pip install hug_middleware_cors
Usage
import hug
from hug_middleware_cors import CORSMiddleware
api = hug.API(__name__)
api.http.add_middleware(CORSMiddleware(api))
@hug.post('/demo')
def demo(name: 'your name'):
return {"result": "Hello {0}".format(name)}
Demoing
- Check out this repository and navigate to its root
- Start a hug server on port 8000 using:
hug -f server.py
- Start a static http server on port 8080 using
python -m http.server 8080
- Go to http://localhost:8080 to send a preflighted CORS request to the hug server.
License
MIT License
See LICENSE for details