Python Flask experiencing strange CORS quirks

My personal website hosted locally at cocostraws.com requires CORS to function properly. I have added the necessary CORS headers for each API link in my Python code.

https://i.sstatic.net/ctysO.png

You can examine the complete files app.py and index.js. This code used to function flawlessly months ago, but now that I've brought it back online, a CORS issue has surfaced. Strangely, if I leave the loaded website idle for some time (around 15 minutes perhaps) and return later, the CORS problem disappears. This erratic behavior is frustrating me as I cannot pinpoint the exact cause. I have exhausted all possible solutions I could think of. Any assistance would be greatly appreciated.


PS: When I switched to using Firefox, the CORS problem vanished. Can anyone shed light on this mystery?

Answer №1

Chrome and Firefox seem to have different interpretations of the HTTP preflight request (Method OPTIONS).

Instead of using wildcard stars '*', it is recommended to use explicit values like:

response.headers.add('Access-Control-Allow-Origin', request.headers.origin);
response.headers.add('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
response.headers.add('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE');

In most cases, the value '*' serves as a special wildcard for requests that do not include credentials (requests without HTTP cookies or authentication information).

Refer to Access-Control-Allow-Origin, Access-Control-Allow-Headers, Access-Control-Allow-Methods, etc.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Store data in LocalStorage according to the selected value in the dropdown menu

Can you help me understand how to update the value of a localstorage item based on the selection made in a dropdown menu? <select id="theme" onchange=""> <option value="simple">Simple</option> <option valu ...

Guidance on calling a JavaScript function from a dynamically added control

The Master page includes a ScriptManager. Next, I have a Control with a ScriptManagerProxy and an UpdatePanel. Within the UpdatePanel, I dynamically insert another Control (which also has a ScriptManagerProxy) that needs to run some JavaScript code. In ...

Formulate a multi-line string using a collection in React's JavaScript framework

I'm working on a React function that involves a set and I need to update an HTML element using the data from this set. Below is an example of my code: const updateElement = (mySet) => { document.getElementById('myId').innerHTML = Arra ...

Is there a way to execute one function before another in JavaScript?

Is there a way to execute the checkifPresentInActiveProjLib function before running the checkifPresentInClosedProjLib function? checkifPresentInActiveProjLib(function(flgAc) { if (flgAc === "active_found") // do something $.ajax(...); / ...

interacting with elements using touch and mouse events in an HTML document

1) Currently developing a standard HTML5 website. Within this site, there are various clickable elements nested within multiple layers of divs. HAML represents this structure as follows: %body #root #content #header #footer One particular div ...

The middleware in Express.js is failing to execute the next function

I have been attempting to run a post function that contains a next(); within the code. To solve this issue, I have exported the function's definition from another file and am trying to call it through an express router. Unfortunately, the function is ...

Sending JSON data from AngularJS to Laravel Controller through POST request

I have encountered an issue while using AngularJS to send POST data to a Laravel controller for saving into a database. The problem lies in the incorrect parsing of data from AngularJS to Laravel. The data being passed looks like this: $scope.invoice_ite ...

PHP Calculator - Displaying results in both the webpage and an Ajax popup for enhanced user experience

UPDATE - the issue was resolved by incorporating $('.popup-with-form').magnificPopup('open'); into the StateChanged function in the JavaScript. Many thanks to @Bollis for the assistance. The Initial Query: I have a basic calculator lo ...

Steps for creating a duplicate of a chosen item in a dropdown menu

Is there a way to specifically select an item from a drop-down menu and duplicate it within the same list? I've come across several solutions where instead of cloning the selected item only, the entire list gets duplicated. For example: function Cop ...

After installing the latest version of [email protected], I encountered an error stating "Module 'webpack/lib/node/NodeTemplatePlugin' cannot be found."

Upon updating to nextjs version 10.1.3, I encountered an error when running yarn dev. Error - ./public/static/style.scss Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin' Require stack: - /path_to/node_modules/mini-css-extract-plugi ...

Currently focused on developing vertical sliders that can be manipulated by dragging them up or down independently

https://i.stack.imgur.com/NgOKs.jpg# I am currently working on vertical sliders that require dragging up and down individually. However, when I pull on the first slider, all sliders move together. The resetAllSliders button should also work independently, ...

Is there a way to efficiently update multiple rows at once in MySQL using an array in Node.js?

I am attempting to use the UPDATE function to modify three different columns in my table named "stores." Specifically, I want to add "openingTime," "closingTime," and "phoneNumber" values and associate them with a storeId that already exists in the table. ...

Utilize the power of REACT JS to transform a specific segment within a paragraph into a hyperlink. Take advantage of the click event on that hyperlink to execute an API request prior to

In React JSX, I'm encountering an issue trying to dynamically convert a section of text into an anchor tag. Additionally, upon clicking the anchor tag, I need to make an API call before redirecting it to the requested page. Despite my attempts, I have ...

Transforming mmddyyyy date format to mm/dd/yyyy using Node.js

Need help converting date format Date: "11032020" (mmddyyyy) Desired output: 11/03/2020 Looking to convert this to mm/dd/yyyy in Node.js as a beginner. I've searched for solutions online but couldn't find one that works for my specific case. ...

Restoring information chart

Here is an example of what I need: click here to view the demonstration Below is the code snippet: var totalRows = $('#tblCatalogo tbody tr').length; for(var i=1; i<=totalRows;i++){ var rs = $('#tblCatalogo tbody tr').children( ...

Deleting items based on identification

When attempting to remove my 3DObject created with three.js using the Id, it doesn't work. However, when using the Name, it works perfectly. Is there a mistake in my approach? scene.remove(scene.getObjectByName("objectname")); //successfully remo ...

Retrieve the designated element from an array of JSON data in SPLUNK

As a newcomer to the world of Splunk, I am facing a challenge with handling JSON data. Here is an example of the JSON data I am working with: "request": { "headers": [ { "name": "x-real-ip", "value": "10.31.68.186" ...

Here's a clever way to utilize Array.map to display two separate React elements without relying on React Fragments

Trying to create this code programmatically: <RadioGroup> <Radio key={1}/> <div>Unique Content 1</div> <Radio key={2}/> <div>Unique Content 2</div> <Radio key={3}/> <div>Unique Content 3& ...

Accessing the current state outside of a component using React Context

As I delve into creating a React application, I find myself in uncharted territory with hooks and the new context API. Typically, I rely on Redux for my projects, but this time I wanted to explore the context API and hooks. However, I'm encountering s ...

I am facing an issue where the table in my Laravel Vue component is not displaying the data from

Recently, I've been diligently following an instructional series on VUE applications by a highly recommended YouTuber. Every step was meticulously executed until I hit a roadblock out of nowhere. The data from my database refuses to display on the fro ...