Skip to content

Commit b8112c0

Browse files
committed
Added CORS notes in README
1 parent 19cb4ed commit b8112c0

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,32 @@ Start the flask app and you can browse to the swagger UI to try out the API::
171171

172172
http://localhost:5000/api/v1/swagger/ui
173173

174+
175+
176+
CORS
177+
====
178+
179+
To enable CORS your API Interface (for Flask this is `ApiBlueprint`) needs to
180+
be wrapped with the CORS wrapper eg::
181+
182+
from flask import Flask
183+
from odinweb.flask import ApiBlueprint
184+
from odinweb.cors import CORS, AnyOrigin
185+
186+
app = flask.Flask(__name__)
187+
188+
app.register_blueprint(
189+
CORS(
190+
ApiBlueprint(
191+
api.ApiVersion(
192+
UserApi()
193+
)
194+
),
195+
origins=AnyOrigin
196+
)
197+
)
198+
199+
For customisation the CORS class can easily be inherited to customise how the
200+
origin is determined (handy if your application is behind a reverse proxy).
201+
The CORS wrapper also accepts `max_age`, `allow_credentials`, `expose_headers`
202+
and `allow_headers` options.

0 commit comments

Comments
 (0)