I added a virtual host abc.local for 127.0.0.1
- Angular app is running on
localhost:4000 - PHP API on
localhost:80 - Node 1 API on
localhost:4060 - Node 2 API on
localhost:3001
PHP files are inside the /admin/webp folder, Node files are inside the /admin/webp/v2 and /admin/webp/v1 folder respectively.
Below is the .htaccess file
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
Header set Access-Control-Allow-Credentials "true"
Header set Access-Control-Allow-Headers "X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding, X-Auth-Token, content-type"
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^abc.local$
RewriteRule ^admin/webp/v2/(.*)$ http://localhost:4060/$1 [L,R=301]
RewriteRule ^admin/webp/v1/(.*)$ http://localhost:3001/v1/$1 [L]
</IfModule>
All rewrite rules are just working fine.
For example all calls to abc.local/webp/v2/users are redirected to localhost:4060/users.
However browser throws CORS error because of the rule
RewriteRule ^admin/webp/v2/(.*)$ http://localhost:4060/$1 [L,R=301]
Apache Server responds OPTIONS request to the node application with a 301 redirect (browser is expecting a 200). Is there any workaround to fix this?