Przeglądaj źródła

update cors configuration

Olivier Massot 6 miesięcy temu
rodzic
commit
597882f943
4 zmienionych plików z 10 dodań i 5 usunięć
  1. 1 1
      api/.env
  2. 1 1
      api/config/packages/nelmio_cors.yaml
  3. 3 3
      app/pages/index.vue
  4. 5 0
      readme.md

+ 1 - 1
api/.env

@@ -26,7 +26,7 @@ DATABASE_URL='mysql://root:Hxb3aMXUPb3m%$Ai*@snc_demo_db:3306/snc_demo?serverVer
 ###< doctrine/doctrine-bundle ###
 
 ###> nelmio/cors-bundle ###
-CORS_ALLOW_ORIGIN='.*'
+CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1|local\.app\.snc-demo\.fr)(:[0-9]+)?$'
 ###< nelmio/cors-bundle ###
 
 ###> symfony/messenger ###

+ 1 - 1
api/config/packages/nelmio_cors.yaml

@@ -3,7 +3,7 @@ nelmio_cors:
         origin_regex: true
         allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']
         allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
-        allow_headers: ['Content-Type', 'Authorization']
+        allow_headers: ['Content-Type', 'Authorization', 'X-Requested-With', 'Accept']
         expose_headers: ['Link']
         max_age: 3600
     paths:

+ 3 - 3
app/pages/index.vue

@@ -2,7 +2,7 @@
   <div>
     <h1 class="text-center mb-6">Authors</h1>
     <v-card v-if="pending" class="text-center pa-4">
-      <v-progress-circular indeterminate />
+      <v-progress-circular :indeterminate="true" />
       <div class="mt-2">Loading authors...</div>
     </v-card>
     <v-card v-else-if="error" class="text-center pa-4 error--text">
@@ -45,10 +45,10 @@ onMounted(async () => {
   try {
     const response = await fetch('https://local.api.snc-demo.fr/api/authors')
     if (!response.ok) {
-      throw new Error(`HTTP error! Status: ${response.status}`)
+      throw new Error(`HTTP error. Status: ${response.status}`)
     }
     const data = await response.json()
-    authors.value = data['hydra:member'] || []
+    authors.value = data['member'] || []
   } catch (err) {
     error.value = err instanceof Error ? err.message : 'Unknown error'
     console.error('Error fetching authors:', err)

+ 5 - 0
readme.md

@@ -40,6 +40,11 @@ Start the nuxt server:
     yarn install
     yarn dev
 
+> **Warning**: You will probably have to open a tab for both of the domains (`local.api.<domain>.fr` and 
+>          `local.api.<domain>.fr`) in your browser to add a security exception for the self-signed SSL certificate.
+> Without it, the frontend's requests will be blocked as CORS errors.
+
+
 ## Add Fixtures
 
 	ALTER TABLE `snc_demo`.`author` AUTO_INCREMENT = 1;