Welcome Guest, Not a member yet? Register   Sign In
Debugbar CORS - Console error
#1
Question 

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?debugba...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? 
Reply
#2

(This post was last modified: 07-08-2021, 09:29 AM by paliz.)

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
Enlightenment  Is  Freedom
Reply
#3

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(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' ?
Reply
#5

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




Theme © iAndrew 2016 - Forum software by © MyBB