Welcome Guest, Not a member yet? Register   Sign In
CORS policy Ci4
#3

(This post was last modified: 07-12-2021, 10:47 AM by paliz.)

thank you

i find another way  i hope work on host too 
combine filter with htaccess 
work 100% on local host 
here code 
got  root document  , public folder then change htaccess

PHP Code:
# Disable directory browsing
Options All -Indexes

# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------

# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
 
Options +FollowSymlinks
 RewriteEngine On

 
# If you installed CodeIgniter in a subfolder, you will need to
 # change the following line to match the subfolder you need.
 # http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
 # RewriteBase /

 # Redirect Trailing Slashes...
 
RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond 
%{REQUEST_URI} (.+)/$
 
RewriteRule ^ %[L,R=301]

 
# Rewrite "www.example.com -> example.com"
 
RewriteCond %{HTTPS} !=on
 RewriteCond 
%{HTTP_HOST} ^www\.(.+)$ [NC]
 
RewriteRule http://%1%{REQUEST_URI} [R=301,L]

 # Checks to see if the user is attempting to access a valid file,
 # such as an image or css document, if this isn't true it sends the
 # request to the front controller, index.php
 
RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond 
%{REQUEST_FILENAME} !-d
 RewriteRule 
^([\s\S]*)$ index.php/$[L,NC,QSA]

 
# Ensure Authorization header is passed along
 
RewriteCond %{HTTP:Authorization} .
 
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]



</
IfModule>

# add this bellow 
<IfModule mod_headers.c>

 
# 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

#        <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"http://localhost:4200"
            Header add Access-Control-Allow-Methods"GET,POST,OPTIONS,DELETE,PUT"
            Header add Access-Control-Allow-Headers"origin, x-api-key, x-requested-with, content-type, accept, access-control-request-method, access-control-allow-headers, authorization, observe, enctype, content-length, x-csrf-token"
            Header add Access-Control-Allow-Credentials true
#        </FilesMatch>

</IfModule>

<
IfModule !mod_rewrite.c>
 
# If we don't have mod_rewrite installed, all 404's
 # can be sent to index.php, and everything works as normal.
 
ErrorDocument 404 index.php
</IfModule>

# Disable server signature start
 
ServerSignature Off
# Disable server signature end 
 
change  corsfilter  like bellow 

PHP Code:
<?php namespace Modules\Common\Filters;

use 
CodeIgniter\config\Services;
use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\Response;
use 
CodeIgniter\HTTP\ResponseInterface;
use 
CodeIgniter\Filters\FilterInterface;


class 
CorsFilter implements FilterInterface
{
    public function after(RequestInterface $requestResponseInterface $response$arguments null)
    {


    }

    public function before(RequestInterface $request$arguments null)
    {
        $method $_SERVER['REQUEST_METHOD'];
        if ($method == "OPTIONS") {
            header("HTTP/1.1 200 OK");
            die();
        }

    }




it  test by me  and got new error 
Code:
main.5ad2075b22ce5575afdc.js:1 ERROR w {headers: h, status: 200, statusText: "OK", url: "http://api.testerdemo.ir/public/api/auth/logout", ok: false, …}error: error: SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at XMLHttpRequest.o (http://www.testerdemo.ir/main.5ad2075b22ce5575afdc.js:1:44368)
    at l.invokeTask (http://www.testerdemo.ir/polyfills.e9e5e2a9498904dca6fa.js:1:7136)
    at Object.onInvokeTask (http://www.testerdemo.ir/main.5ad2075b22ce5575afdc.js:1:150200)
    at l.invokeTask (http://www.testerdemo.ir/polyfills.e9e5e2a9498904dca6fa.js:1:7057)
    at t.runTask (http://www.testerdemo.ir/polyfills.e9e5e2a9498904dca6fa.js:1:2532)
    at u.invokeTask [as invoke] (http://www.testerdemo.ir/polyfills.e9e5e2a9498904dca6fa.js:1:8186)
    at _ (http://www.testerdemo.ir/polyfills.e9e5e2a9498904dca6fa.js:1:20119)
    at XMLHttpRequest.k (http://www.testerdemo.ir/polyfills.e9e5e2a9498904dca6fa.js:1:20443)message: "Unexpected token < in JSON at position 0"stack: "SyntaxError: Unexpected token < in JSON at position 0\n    at JSON.parse (<anonymous>)\n    at XMLHttpRequest.o (http://www.testerdemo.ir/main.5ad2075b22ce5575afdc.js:1:44368)\n    at l.invokeTask (http://www.testerdemo.ir/polyfills.e9e5e2a9498904dca6fa.js:1:7136)\n    at Object.onInvokeTask (http://www.testerdemo.ir/main.5ad2075b22ce5575afdc.js:1:150200)\n    at l.invokeTask (http://www.testerdemo.ir/polyfills.e9e5e2a9498904dca6fa.js:1:7057)\n    at t.runTask (http://www.testerdemo.ir/polyfills.e9e5e2a9498904dca6fa.js:1:2532)\n    at u.invokeTask [as invoke] (http://www.testerdemo.ir/polyfills.e9e5e2a9498904dca6fa.js:1:8186)\n    at _ (http://www.testerdemo.ir/polyfills.e9e5e2a9498904dca6fa.js:1:20119)\n    at XMLHttpRequest.k (http://www.testerdemo.ir/polyfills.e9e5e2a9498904dca6fa.js:1:20443)"__proto__: Errortext: "<br />\n<b>Parse error</b>:  syntax error, unexpected ':', expecting '{' in <b>/home3/esterdem/api.testerdemo.ir/system/Common.php</b> on line <b>49</b><br />\n"__proto__: Objectheaders: hlazyInit: ()=> {…}lazyUpdate: nullnormalizedNames: Map(0) {}__proto__: Objectmessage: "Http failure during parsing for http://api.testerdemo.ir/public/api/auth/logout"name: "HttpErrorResponse"ok: falsestatus: 200statusText: "OK"url: "http://api.testerdemo.ir/public/api/auth/logout"__proto__: q

work fine on local host but on live host still not working
shit hillllllllllllll
Enlightenment  Is  Freedom
Reply


Messages In This Thread
CORS policy Ci4 - by paliz - 07-11-2021, 12:31 PM
RE: CORS policy Ci4 - by includebeer - 07-12-2021, 07:19 AM
RE: CORS policy Ci4 - by paliz - 07-12-2021, 09:58 AM
RE: CORS policy Ci4 - by paliz - 07-12-2021, 11:01 AM
RE: CORS policy Ci4 - by paliz - 07-12-2021, 06:30 PM
RE: CORS policy Ci4 - by includebeer - 07-13-2021, 10:49 AM
RE: CORS policy Ci4 - by paliz - 07-13-2021, 11:58 AM
RE: CORS policy Ci4 - by paliz - 07-13-2021, 01:02 PM
RE: CORS policy Ci4 - by includebeer - 07-13-2021, 01:49 PM
RE: CORS policy Ci4 - by paliz - 07-13-2021, 01:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB