I'm trying to embed a React app inside a page rendered by a Drupal 9.4.x site.
It works fine on the online server, with the build script. However, if i try to load the page locally, with the development server, I get the CORS error:
Access to script at 'http://localhost:9000/react-app.js' from origin 'https://drupalsite.ddev.site' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Theoretically the Drupal back-end is configured correctly for the CORS.
The service.yml
configuration about is:
cors.config:
enabled: true
# Specify allowed headers, like 'x-allowed-header'.
allowedHeaders: [ 'Access-Control-Allow-Origin', 'Accept', 'Content-Disposition', 'Content-Type', 'x-csrf-token', 'content-type', 'content-disposition', 'authorization' ]
# Specify allowed request methods, specify ['*'] to allow all possible ones.
allowedMethods: [ '*' ]
# Configure requests allowed from specific origins.
allowedOrigins: [ 'http://localhost', 'http://localhost:9000', 'https:/www.onlinesite.com' ]
# Sets the Access-Control-Expose-Headers header.
exposedHeaders: false
# Sets the Access-Control-Max-Age header.
maxAge: false
# Sets the Access-Control-Allow-Credentials header.
supportsCredentials: true
The script is embeded in a twig in this way:
<link rel="stylesheet" href="http://localhost:9000/style.css"/>
<script type="module" src="http://localhost:9000/react-app.js"></script>
Do I need to configure something on React? The React app is done with React 17.0.2 and Craco 6.1.1.