![]() |
Add CORS headers to 404 page - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Add CORS headers to 404 page (/showthread.php?tid=86691) Pages:
1
2
|
Add CORS headers to 404 page - ozornick - 02-12-2023 I have configured headers for requests. It works great. But when the browser sends CORS the OPTIONS pre request, my filter won't work for 404 pages. Where is the best place for me to fix this behavior? Code: Request URL: http://api.me/users/register2 RE: Add CORS headers to 404 page - InsiteFX - 02-12-2023 Please show your code where you are setting the CORS headers so that we can help you. RE: Add CORS headers to 404 page - ozornick - 02-12-2023 i add filter to $before global in Filters. In filter method before() set new response if request method OPTIONS and return $response->setHeader(...) Oh, I may have found a mistake - always add 200 status. I'll try later RE: Add CORS headers to 404 page - InsiteFX - 02-12-2023 Ok, let me know how you make out with this problem. RE: Add CORS headers to 404 page - ozornick - 02-13-2023 No. I set status code. But filter not loaded by 404 page PHP Code: public function before(RequestInterface $request, $arguments = null) RE: Add CORS headers to 404 page - InsiteFX - 02-13-2023 Try changing the below, I do my CORS in the .htaccess file. PHP Code: // Change this RE: Add CORS headers to 404 page - ozornick - 02-13-2023 No, no. Problem is specifically in the filters. They do not apply to the 404 page. I do a "stop as dd()" in filter, but it doesn't even work. In normal mode, my headers (with *) are sent without errors RE: Add CORS headers to 404 page - InsiteFX - 02-14-2023 I don't know who wrote this CORS Filter but here goes. You may need to change the namespace etc for yours. PHP Code: <?php RE: Add CORS headers to 404 page - ozornick - 02-14-2023 It eqal my filter. But i return $response, in your example hard exit(). This won't work because the high-level filter isn't called. My dd() didn't stop RE: Add CORS headers to 404 page - kenjis - 08-04-2023 @ozornick Why do you need to apply filters to 404 page? For what? |