Get origin of the request in notebook_config.py

I would like to set c.NotebookApp.allow_origin dynamically based on the request’s origin. How can I obtain the request’s origin at runtime and set this value?

https://github.com/jupyter/jupyter/issues/79 and https://github.com/jupyterhub/jupyterhub/issues/1087 were helpful but could’t get the entire picture to solve this.

c.NotebookApp.allow_origin_pat can be used to set multiple allowed origins. The Jupyter server will set the corresponding origin URL if it matches the pattern mentioned. Thanks @minrk for the tip!