So I have this json-server setup in my vue3 project and everything just works fine until this one endpoint /leads throwing me this error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://mydomain/leads. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 403.
I'm not sure why because the other endpoint which is /inquiries with the same code, a copy-pasted code is working even without the cors npm package.
But I installed it anyway just to make sure cors is setup for all my enpoints. But I'm still getting the same error.
So I would run the json-server like this:
json-server db.json --watch --middlewares cors.js
Here's my cors.js file:
const jsonServer = require('json-server')
// Import the library:
const cors = require('cors')
const server = jsonServer.create()
// Then use it before your routes are set up:
server.use(cors())
module.exports = cors()
Here's both /leads and /inquiries endpoint with the same request headers:
