Skip to content

Document common cors configuration issues #350

@markphelps

Description

@markphelps

we had a user in discord note that CORS config wasnt working with their browser based app (Vue) when trying to issue a client side evaluation request using the official Flipt JS SDK:


Conversation:

I have Flipt v2 running locally using the following config

credentials:
  github-api:
    access_token: {REDACTED}
    type: access_token
cors:
  enabled: false
environments:
  default:
    default: true
    directory: flipt
    name: default
    scm:
      credentials: github-api
      type: github
    storage: default
storage:
  default:
    backend:
      type: memory
    branch: main
    credentials: github-api
    poll_interval: 30s

but when my client makes this request, it's getting rejected for CORS. What am I doing wrong here?
http://localhost:8080/internal/v1/evaluation/snapshot/namespace/default

<template>flag is {{ flagState }}</template>

<script setup lang="ts">
import { FliptClient } from '@flipt-io/flipt-client-js';
import { onMounted, ref } from 'vue';
const flagState = ref(false);
onMounted(async () => {
  try {
    const client = await FliptClient.init({
      namespace: 'default',
      url: 'http://localhost:8080/',
    });
    const response = client.evaluateBoolean({
      flagKey: 'sdf',
      entityId: 'someentity',
      context: {
        fizz: 'buzz',
      },
    });
    console.log('Flag evaluation response:', response);
    flagState.value = response.enabled;
  } catch (error) {
    console.error('Error initializing Flipt client:', error);
  }
});
</script>

I'm using Vue and the official SDK

Image

They said that even when they set cors.enabled to true, it still didnt fix the issue. They were on the Microsoft Edge Browser (latest version).

What did eventually work was when they configured the cors config explicitly, instead of relying on the defaults like:

cors:
  enabled: true
  allowed_origins:
    - http://localhost:5173
  allowed_methods: [GET, POST, OPTIONS]
  allowed_headers:
    - Content-Type
    - Authorization
    - X-Requested-With
    - x-flipt-environment

We should document some common issues when configuring CORS and how to fix them

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions