Welcome to the Linux Foundation Forum!

Mocking GET Routes (5) : missing cors options

The example code does not work at all.

Error:

Access to fetch at 'http://localhost:3000/confectionery' from origin 'http://localhost:5050' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Here is my modified solution:

fastify.register(cors, { origin: "*", // Allow requests from any origin methods: ["GET", "HEAD", "POST"], // Allow specific HTTP methods allowedHeaders: ["Content-Type", "Authorization"], // Allow specific headers credentials: true, // Allow credentials (cookies, authorization headers, etc.) });

did not work without the
origin: "*"

Categories

Upcoming Training