Cornice: define CORS policy in configuration?

38 views
Skip to first unread message

Jens W. Klein

unread,
Jan 8, 2018, 6:23:40 AM1/8/18
to pylons-...@googlegroups.com
I have a small application where I want to configure `cors_origins`
different dependent on the server its running on (dev/ staging/ live)
without allowing access cross those domains.

At the moment I have a policy defined in Python in a base.py, import it
and use it in my classes with the enpoint like so:

CORS_POLICY = {
'origins': ('*.dev.myserver'.com,),
#'origins': ('*.stage.customerserver.com',),
#'origins': ('*.livedomain.com',),
...,
}

---

@resource(path='/api/menu', cors_policy=CORS_POLICY)
class Menu(object):

def get(self):
...
return menu_def
---

Question: is there a way to define the `cors_origin` in the INI-files?

TIA Jens
--
Klein & Partner KG, member of BlueDynamics Alliance

Laurent DAVERIO

unread,
Jan 8, 2018, 9:27:39 AM1/8/18
to pylons-...@googlegroups.com
Hi Jens,

if you want to define the value in INI files, it will need to be read in
a function where either "config" or "settings" is available.

One way to do that would be to define CORS_POLICY as a global variable
in your app and initialize it using a config.include() call in your
__init__.py.

Hope this helps,

Laurent.
Reply all
Reply to author
Forward
0 new messages