Like what we’re doing? Star us on GitHub!

CORS issues even when origins specified

thisisnotchris
2 weeks ago
3

Not sure what I'm doing wrong here



export default buildConfig({
  serverURL: "https://beta.safsonline.com",
  admin: {
    user: Admins.slug,
  },
  cors: ["http://localhost:4200", "http://safsbeta1.safsonline.com", "http://safsbeta2.safsonline.com"],
  csrf: ["http://localhost:4200", "http://safsbeta1.safsonline.com", "http://safsbeta2.safsonline.com"],
  collections: [Admins, Users, Pages, Media, Documents],
  typescript: {
    outputFile: path.resolve(__dirname, "payload-types.ts"),
  },
  graphQL: {
    schemaOutputFile: path.resolve(__dirname, "generated-schema.graphql"),
  },
  routes: {
    api: '/payload/api',
    admin: '/payload/admin',
    graphQL: '/payload/graphql',
    graphQLPlayground: '/payload/graphql-playground'
  }
});


and in server



app.use(express.json());
app.use(
  cors({
    
    origin: ["http://localhost:4200", "http://safsbeta1.safsonline.com", "http://safsbeta2.safsonline.com"],
    credentials: true,
  })
);
image.png
  • MichaelBOOM
    last week

    You are getting the error on an https URL and only have http URLs listed. Maybe try changing your (what I assume is a production) safsbeta1.safsonline.com URL to https? Also if the 2nd snippet is from the same server that payload uses, I didn't need to set any CORS settings manually on the express instance.

Open the post
Continue the discussion in Discord
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More