Dynamic cors

Implementing 2nd method from issue #1772

__Why is it needed:__ To dynamically check whether origin is allowed to access, when hard-coded origins are not an option (for example based on values in database that dynamically change).