CodeIgniter Forums
Debugbar CORS - Console error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Debugbar CORS - Console error (/showthread.php?tid=79619)



Debugbar CORS - Console error - AndrewDawnbringer - 07-08-2021

Hy. I'm getting these console messages on my site, running CI4:

Quote:Access to XMLHttpRequest at 'https://www.domain.com/index.php?debugbar_time=1625747857' from origin 'https://domain.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

index.php?debugbar:59 GET https://www.domain.com/index.php?debugbar_time=1625747857 net::ERR_FAILED
loadDoc @ index.php?debugbar:59



Of course I googled it, made a filter for it, and I also put the 'Access-Control-Allow-Origin' header into the Controller, but I'm still getting this error. What am I doing wrong? 


RE: Debugbar CORS - Console error - paliz - 07-08-2021

Use sub domain Api.Exmple. Com
Upload ci4 there And Exmple.com for anguar or react

Yoi need cors filter too
It has be global and init before other filters


RE: Debugbar CORS - Console error - InsiteFX - 07-08-2021

Add to your .htaccess file along side where index.php is.
Code:
    ## For CORS Configuration

    # Add Font Types
    AddType application/vnd.ms-fontobject .eot
    AddType application/x-font-ttf        .ttf
    AddType application/x-font-opentype  .otf
    AddType application/font-woff        .woff
    AddType application/font-woff2        .woff2

    <IfModule mod_headers.c>
        <FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|svg|svgz|jpg|png|ico|font.css|css|js)$">
            ## un-remark this one for all access and remark out the one below it
            #Header set Access-Control-Allow-Origin "*"
            ## Change this to your local host url. and https or http
            Header add Access-Control-Allow-Origin: "https://your.com"
            Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
            Header add Access-Control-Allow-Headers: "Upgrade-Insecure-Requests"
        </FilesMatch>
    </IfModule>

    # Remove index.php from URL
    RewriteCond %{HTTP:X-Requested-With}    !^XMLHttpRequest$
    RewriteCond %{THE_REQUEST}              ^[^/]*/index\.php [NC]
    RewriteRule ^index\.php(.*)$            $1 [R=301,NS,L]

Try that, it's what I use.


RE: Debugbar CORS - Console error - AndrewDawnbringer - 07-11-2021

(07-08-2021, 09:18 AM)paliz Wrote: Use sub domain Api.Exmple. Com
Upload ci4 there And Exmple.com  for anguar or react


Is it something for only Angular / React? Didn't planned to use those, so I'm a bit confused. Isn't it 'PHP debugbar' ?


RE: Debugbar CORS - Console error - AndrewDawnbringer - 07-11-2021

Thanks, I solved the issue following this guide, using Nginx.