keystonejs / keystone

The most powerful headless CMS for Node.js — built with GraphQL and React
https://keystonejs.com
MIT License
8.98k stars 1.13k forks source link

Cannot set CORS #9178

Closed mandymozart closed 1 week ago

mandymozart commented 1 week ago

I am trying for some time now, to create a simple backend for a simple React App but use the keystone admin ui to provide data for my project, but am failing to link any external client due to CORS errors.

setting the underlying express.js CORS manually (as described in the docs) does not work, neither locally nor deployed on render.com

The app is not a production ready thing. It's a prototype and therefore I do not need to protect my app. I want to allow * for now. I tried all bellow variants.

import 'dotenv/config'
import { config } from '@keystone-6/core';
import { lists } from './schema';
import { withAuth, session } from './auth';

const {
  DB_USER,
  DB_PASSWORD,
  DB_HOST,
  DB_PORT,
  DB_NAME,
  S3_BUCKET_NAME: bucketName,
  S3_REGION: region,
  S3_ACCESS_KEY_ID: accessKeyId,
  S3_SECRET_ACCESS_KEY: secretAccessKey,
} = process.env

export default withAuth(
  config({
    db: {
      provider: 'mysql',
      url: `mysql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}`
      // url: 'file:./keystone.db',
    },
    lists,
    session,
    server: {
      cors: undefined
        // cors: { origin: ['*','http://localhost','http://127.0.0.1'] },
    },
    graphql: {
      cors: undefined
      // cors: { origin: ['*','http://localhost','http://127.0.0.1'] },
    },
    storage: {
      my_images: {
        kind: 's3',
        type: 'image',
        bucketName,
        region,
        accessKeyId,
        secretAccessKey,
        signed: { expiry: 5000 },
      },
      my_files: {
        kind: 's3',
        type: 'file',
        bucketName,
        region,
        accessKeyId,
        secretAccessKey,
        signed: { expiry: 5000 },
      },
    }
  })
);

Thank you.

mandymozart commented 1 week ago

Additional Info: also adding the port property in server does not change anything.