[add] cors

This commit is contained in:
2018-08-05 20:50:33 -06:00
parent 59472e5650
commit 120e07b315
3 changed files with 127 additions and 3 deletions

View File

@@ -2,3 +2,21 @@
// Application middleware
// e.g: $app->add(new \Slim\Csrf\Guard);
// Enable cors
$app->add(new \Tuupola\Middleware\Cors([
"origin" => ["*"],
"methods" => ["GET", "POST", "PUT", "PATCH", "DELETE"],
"headers.allow" => ["Accept", "Content-Type"],
"headers.expose" => [],
"credentials" => false,
"cache" => 0,
"logger" => $container['logger'],
"error" => function ($request, $response, $arguments) {
$data["status"] = "error";
$data["message"] = $arguments["message"];
return $response
->withHeader("Content-Type", "application/json")
->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
}
]));