CORS for Trellis site to allow requests for SVG

My staging/production environment unfortunately uses Apache, which you suggested earlier is not really a good idea.. I really like Trellis however, so I would really like to use it despite that.

Right now I’m building headless website (React on front-end, WP powered by Trellis on back-end). I need to inline SVG uploaded to WP’s backend to my front-end. Http call results to this error: No 'Access-Control-Allow-Origin' header is present on the requested resource.

React front-end requesting SVG from the Trellis site (examplewp.test) is on localhost:3000 domain.

I’ve tried to add those lines …

location ~* \.(eot|svg|ttf|woff|woff2|json)$ {
	add_header 'Access-Control-Allow-Origin' "*";
	add_header 'Vary' "Origin";
}

… to following locations:

  • <TRELLIS-FOLDER>/nginx-includes/all/cors.conf.j2
  • <TRELLIS-FOLDER>/nginx-includes/<NAME-OF-SITE>/cors.conf.j2
  • vagrant ssh and sudo nano /etc/nginx/sites-enabled/<NAME-OF-SITE>.conf

Error I’ve posted about persists however.

Can you tell me what am I doing wrong? Thanks in advance!

1 Like

Trellis is designed with the idea that it’s in charge of your production environment, so you might find yourself frustrated trying to force it to interact with an existing Apache environment.

Is there a reason you can’t provision your production environment with Trellis?