If have the following configuration for vite:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import * as fs from 'fs';
// https://vitejs.dev/config/
export default defineConfig({
server: {
proxy: {
},
cors: {
origin: '*',
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
preflightContinue: true
},
https: {
key: fs.readFileSync('./.cert/key.pem'),
cert: fs.readFileSync('./.cert/cert.pem'),
}
},
define: {
'process.env': {}
},
plugins: [react()],
})
Also tried this with ...cors:true... From my react code i try to acces the following json api https://gegevensmagazijn.tweedekamer.nl/OData/v4/2.0/persoon
This always result in a CORS error I can access this api from my pc directly with chrome and with postman.
I call it with this piece of javascript as a test:
const response = await fetch("https://gegevensmagazijn.tweedekamer.nl/OData/v4/2.0/persoon");
const person = await response.json();
console.log(person);
Does anyone know how to configure the server and the fetch or axios call to accept CORS?
Turns out, you can't directly go to this api from javascript. I created a small API parser in C#. which passes the OData from the source. This works.