You are developing a web application that needs to make API requests to a server on a different domain. How would you handle CORS to ensure that your web application can interact with the server without any issues?
- Set up a server-side proxy to forward requests to the other domain.
- Enable CORS on the server by adding appropriate headers to allow cross-origin requests.
- Use JSONP for making cross-domain requests.
- Disable CORS restrictions in the browser settings.
The correct approach is to enable CORS on the server by adding the appropriate headers that allow cross-origin requests. Option A can be a workaround, but it's not the best practice. Option C is an outdated method, and option D is not a recommended security practice.
Loading...
Related Quiz
- You are building a real-time data processing system where tasks are dependent on the completion of previous tasks. How would you structure your Promises/async functions to ensure the sequence is maintained?
- What is the primary advantage of using connection pooling when interacting with a database?
- In JavaScript, altering an object’s prototype at runtime can lead to ______ performance impacts.
- Named imports in JavaScript must match the exported names in the module, unless they are ________.
- How can you use the fs module to copy a file from one location to another?