Added gobal API cors hostname config

This commit is contained in:
Frank Schubert
2023-04-03 15:42:28 +02:00
parent be9bbee758
commit e2345cb08f

View File

@@ -43,6 +43,13 @@ class mfBaseApicontroller {
register_shutdown_function(["mfBaseApicontroller", "return_errors"]);
// allow origins from config file
if(defined("API_CORS_ALLOWED_HOSTNAMES") && is_array(API_CORS_ALLOWED_HOSTNAMES)) {
foreach(API_CORS_ALLOWED_HOSTNAMES as $origin) {
$this->addAllowedOrigin($origin);
}
}
// CORS preflight
// allow all origins
if($this->http_method == "OPTIONS") {
@@ -71,7 +78,7 @@ class mfBaseApicontroller {
if($this->requireAuth) {
$this->authenticateUser();
if(method_exists($this,"authenticated")) {
$this->authenticated();
$this->authenticated(); // event defined in extending class
}
}