/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if ($request->isMethod('options')) { return $this->addCORSHeaders(response('', 200)); } $request = $next($request); if (Subdomens::is('api')) { $request = static::addCORSHeaders($request); } return $request; }
/** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * @return \Illuminate\Http\Response */ public function render($request, Exception $e) { $debug = config("app.debug"); $debugbar = $debug && config("debugbar.enabled") !== false && !$request->ajax(); if (app()->environment('local')) { if ($request->ajax()) { $handler = new \Whoops\Handler\JsonResponseHandler(); } else { $handler = new \Whoops\Handler\PrettyPageHandler(); $handler->setEditor('sublime'); } $whoops = new \Whoops\Run(); $whoops->pushHandler($handler); $whoops->allowQuit(false); $whoops->writeToOutput(true); $status = 500; $headers = []; if ($e instanceof HttpExceptionInterface) { $status = $e->getStatusCode(); $headers = $e->getHeaders(); } $response = response($whoops->handleException($e), $status, $headers); } else { $response = parent::render($request, $e); } if ($debugbar) { $debugbar = app()->make('debugbar'); $debugbar->boot(); $debugbar->addException($e); $response = $debugbar->modifyResponse($request, $response); } if (Subdomens::is('api')) { $response = Api::addCORSHeaders($response); } return $response; }
protected function shouldPassThrough($request) { return parent::shouldPassThrough($request) || Subdomens::is("api"); }
public static function isApiCall() { return Subdomens::is('api'); }