dweber019 / backstage-plugins

A collection of Backstage plugins
MIT License
20 stars 7 forks source link

Access to fetch at 'https://endoflife.date/api/springboot.json' from origin 'xx' has been blocked by CORS policy. #3

Closed bameur closed 6 months ago

bameur commented 6 months ago

Hello.

I have a blockage because of the cors policy. I had to do some research with no results. Here is the error message : Access to fetch at 'https://endoflife.date/api/springboot.json' from origin 'https://xxxxxxx.yy' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Do you have any idea to solve it?

Bests regards

dweber019 commented 6 months ago

Hi

Can you provide the configuration/annotations you used in your example.

bameur commented 6 months ago

Hi.

My config :

# Backstage override configuration for your local development environment
backend:
  database:
    client: pg
    connection:
      host: 192.168.x.x
      port: 5432
      user: backstage
      password: xxxxxxxx

integrations:
  gitlab:
    - apiBaseUrl: https://gitlab.domaine.com/api/v4
      host: gitlab.domaine.com
      token: xxxxxxxxxxxxxxxxxxxxxxxxxxx

sonarqube:
  baseUrl: http://sonar.domaine.com
  apiKey: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

proxy:
  ### Example for how to add a proxy endpoint for the frontend.
  ### A typical reason to do this is to handle HTTPS and CORS for internal services.
  endpoints:
    '/gitlab/api/':
      target: 'https://gitlab.domaine.com/api/v4'
      allowedHeaders: ['Authorization', 'Content-Type']
      headers:
        Accept: application/json 
        Content-Type: application/json

#enableExperimentalRedirectFlow: true
auth:
  # see https://backstage.io/docs/auth/ to learn about auth providers
  environment: development
  providers: 
    gitlab:
      development:
        clientId: ${AUTH_GITLAB_CLIENT_ID}
        clientSecret: ${AUTH_GITLAB_CLIENT_SECRET}
        ## uncomment if using self-hosted GitLab
        audience: https://gitlab.domaine.com
        ## uncomment if using a custom redirect URI
        # callbackUrl: https://${BASE_URL}/api/auth/gitlab/handler/frame
  # see https://backstage.io/docs/auth/autologout
  autologout:
    enabled: true
    idleTimeoutMinutes: 30
    useWorkerTimers: false 
    logoutIfDisconnected: false

catalog:
  providers:
    gitlab:
      yourProviderId:
        host: gitlab.domaine.com
        orgEnabled: true
        # group: org/teams # Required for gitlab.com when `orgEnabled: true`. Optional for self managed. Must not end with slash. Accepts only groups under the provided path (which will be stripped)
        groupPattern: '[\s\S]*' # Optional. Filters found groups based on provided pattern. Defaults to `[\s\S]*`, which means to not filter anything
        schedule: # optional; same options as in TaskScheduleDefinition
          # supports cron, ISO duration, "human duration" as used in code
          frequency: { minutes: 30 }
          # supports ISO duration, "human duration" as used in code
          timeout: { minutes: 3 }

Annotation:

---
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
  name: si-data-services-backend
  annotations:
    endoflife.date/products: springboot
    sonarqube.org/project-key: 598
    gitlab.com/project-slug: com/data/si-data-service-backend 
    backstage.io/techdocs-ref: dir:.
  description: 
    Reel time Datalake
  links :
    - url: https://elk.com:5601/app/home#/ 
      title: elk
  tags:
    - springboot320
    - java17
    - kube

Error Frontend: image

Trace: image

thank you for your help

dweber019 commented 6 months ago

What I found is that springboot will respond with a redirect

https://endoflife.date/api/springboot.json
301 Moved Permanently

Can you try https://endoflife.date/api/spring-boot.json

endoflife.date/products: spring-boot
bameur commented 6 months ago

I just tested it, it looks good 👋 Thank you for your help.

dweber019 commented 6 months ago

Nice, maybe the redirect enforces CORS. I created an issue at endoflife.date.