/** * @param $routePattern mixed if array it will set as headers * @param null $handler * @return Application|\Phalcon\Mvc\Router\RouteInterface */ public function options($routePattern, $handler = null) { if (!$handler or !is_callable($handler)) { return $this->optionsMaps(); } return parent::options($routePattern, $handler); }
echo "</pre>"; } //Create and bind the DI to the application $app = new Micro($di); $app->get('/', function () use($app) { echo 'Welcome to kajian API'; }); foreach (glob("routes/*.php") as $filename) { include $filename; } $app->notFound(function () use($app) { $app->response->setStatusCode(404, "Not Found")->sendHeaders(); echo 'This is crazy, but this page was not found!'; }); $app->before(function () use($app) { $origin = $app->request->getHeader("ORIGIN") ? $app->request->getHeader("ORIGIN") : '*'; $content_type = 'application/json'; $status = 200; $description = 'OK'; $response = $app->response; $status_header = 'HTTP/1.1 ' . $status . ' ' . $description; $response->setRawHeader($status_header); $response->setStatusCode($status, $description); $response->setContentType($content_type, 'UTF-8'); $response->setHeader("Access-Control-Allow-Origin", $origin)->setHeader("Access-Control-Allow-Methods", 'GET,PUT,POST,DELETE,OPTIONS')->setHeader("Access-Control-Allow-Headers", 'Origin, X-Requested-With, Content-Range, Content-Disposition, Content-Type, Authorization')->setHeader("Access-Control-Allow-Credentials", true)->setHeader('Content-type', $content_type); $response->sendHeaders(); }); $app->options('/{catch:(.*)}', function () use($app) { $app->response->setStatusCode(200, "OK")->send(); }); $app->handle();