im running 2 docker containers for some local testing. One is an API at websites.click
, the other is webplanner.click:8081
.
I'm attempting to request some data from my endpoint at websites.click/api/cache/clear-all
, however im getting the following error:
Access to XMLHttpRequest at 'http://websites.click/api/cache/clear-all' from origin 'http://webplanner.click:8081' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
I'm requesting the data using Axios
as follows:
window.axios.get('//websites.click/api/cache/clear-all', {
}).then(response => {
console.log(response);
})
Now i'm assuming the issue is within my htaccess
as the error mentions preflight redirect. This is the htaccess within websites.click/api/
RewriteEngine On
RewriteBase /api
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?request=$1 [QSA,NC,L]
Options All +Indexes
allow from all
I have also added the following to my /api/index.php
which contains the Routes.
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
Edit 1:
Made the recommended changes by removing the headers wet within the ajax
request, still getting the same error:
Access to XMLHttpRequest at 'http://websites.click/api/cache/clear-all/' from origin 'http://webplanner.click:8081' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
This is the request within the XHR tab:
Request URL: http://websites.click/api/cache/clear-all/
Accept: application/json, text/plain, */*
Referer: http://webplanner.click:8081/admin/cache
X-Requested-With: XMLHttpRequest
X-Socket-Id: 126436.7368245