Unable to access resource due to lack of 'Access-Control-Allow-Origin' header in the CORS policy (Node.js)

When I launch my frontend on Chrome, I keep encountering these two errors in the console.

Access to XMLHttpRequest at 'https://hog.simplify.jobs/decide/?v=3&ip=1&_=1688782636903&ver=1.57.2' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

POST https://hog.simplify.jobs/decide/?v=3&ip=1&_=1688782636903&ver=1.57.2 net::ERR_FAILED 404 contentScript.bundle.js:1 

I've attempted to resolve this issue by installing the Chrome extension, but unfortunately, it hasn't helped. Additionally, I've tried updating my backend code with either of the following:

app.use(cors({origin: '*'}));

or

app.use(function (req, res, next) {
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With, content-type');
    res.setHeader('Access-Control-Allow-Credentials', true);
    next();
});

However, neither approach has resolved the problem.

Answer №1

Due to security reasons, accessing this website from the front end is restricted. Instead, it is recommended to handle this operation on the backend using a library like Axios.

To learn more about why this restriction exists, please visit this link

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

The situation arose when Webpack unexpectedly terminated before completion

Currently, I'm facing an issue with my project that I've been developing using Vaadin 14.4.10 and Node.js 14.16.1 without any hassle until now. The only recent change I made was updating the Vaadin version to 23.3.6 while working in a local branc ...

Ensure your server stays alive and active with ReactPHP, just like the "pm2" process manager for "NodeJS"

I was recently taking a deep dive into learning about the fascinating world of "ReactPHP", but I ran into a bit of confusion regarding how to keep it running on the server in case of errors. After some research, I discovered that "NodeJS" has a handy tool ...

Module not found, missing module error #557

Upon completing the command npm install -g @vue/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="482b2421087b66786678652a2d3c296671">[email protected]</a>, I proceeded with the command vue create client and encount ...

Having difficulty upgrading NPM on Ubuntu Server version 16.04

I am facing an issue while attempting to update NPM on my Ubuntu Server (16.04) as the upgrade process is not working correctly. npm -v displays 3.5.2 After executing sudo npm install npm@latest -g The output is as follows: /usr/local/bin/npm -> ...

RS256 algorithm not utilized for Node.js JWT token generation

For my node.js REST api calls, I implemented JWT as a security measure. Below is the code snippet I used to generate the token: jwt.sign({ foo: 'bar' }, private_key, { algorithm: 'RS256'}, (err, token) => { res.json({ ...

Deactivate the remotebuild agent on a Mac to ensure security is not compromised

I am currently working on developing an app using Cordova on my Mac. To facilitate this process, I installed the remotebuild package via npm. After completing the installation, it was necessary to set "remotebuild --secure false" but when attempting to d ...

Error encountered when trying to update Express Mongoose due to duplicate key

In my MongoDB database, I have a unique field called mail. When attempting to update a user, I encounter an issue where if I do not change the mail field, it triggers a duplicate key error. I need a solution where it is not mandatory to always modify the ...

The error message states: "TypeError: a.map is not a function"

I recently deployed my React JS app on Heroku and encountered some issues with the routing. While everything worked smoothly on my local host, I faced errors after fixing the routing problem that I couldn't resolve. Despite extensive research, I haven ...

What could be causing me to receive empty objects in my post requests with Express?

I am experiencing difficulties with this code as I am only receiving empty objects when using Postman. app.use(express.urlencoded({extended: true})); app.use(express.json()); router.post('/', (req, res, next) => { const product = { nam ...

The npm command returns an error message stating "Either an insufficient amount of arguments were provided or no matching entry was found."

I'm trying to pass a custom flag from an npm script to my webpack config, but I keep encountering the following error in the logs: Insufficient number of arguments or no entry found. Alternatively, run 'webpack(-cli) --help' for usage info. ...

Where is the first next() call's argument located?

I'm facing an issue with a simple generator function function *generate(arg) { console.log(arg) for(let i = 0; i < 3;i++) { console.log(yield i); } } After initializing the generator, I attempted to print values in the console: var gen ...

Error encountered in my application due to Node.js (Error [ERR_HTTP_HEADERS_SENT]: Unable to change headers once they have been sent to the client)

Experiencing an error message in my application when typing nodeJS. Please assist. , Encountering an error after sending the first POST request while running the app. const express = require('express') const Workout = require("../models/work ...

Jest is unable to handle ESM local imports during resolution

I am encountering an issue with my Typescript project that contains two files, a.ts and b.ts. In a.ts, I have imported b.ts using the following syntax: import * from "./b.js" While this setup works smoothly with Typescript, Jest (using ts-jest) ...

Is there a solution available for the error message that reads: "TypeError: Cannot set value to a read-only property 'map' of object '#<QueryCursor>'"?

Everything was running smoothly in my local environment, but once I deployed it on a Digital Ocean Kubernetes server, an error popped up. Any assistance would be greatly appreciated. https://i.stack.imgur.com/VxIXr.png ...

data storage using sessionstorage for session management

Currently, I am managing sessions in my MEAN app by utilizing AngularJS to store user data in the browser's sessionStorage. The process consists of: User logs in through the front-end User is fetched from the back-end (node) Returned data is saved t ...

Is it feasible to duplicate the node_modules directory instead of reinstalling it each time for create-react-app?

As a newcomer to React, I am in the process of creating simple applications by following tutorials to become more acquainted with React. However, it is frustrating that every time I create a new react app using create-react-app, I have to download the enti ...

What is the method for performing calculations and retrieving data from an array in this scenario?

The process involves retrieving data from the database and populating an array named rows, which is used to calculate invoiceSubtotal (using the subtotal function), invoiceTaxes, and invoiceTotal. Even though the data is successfully stored in the array, t ...

Encountering the error message "npm unable to locate package.json file" while attempting to execute a nestjs project

Currently, I am diving into a nestjs tutorial on YouTube. Initially, I had set up nodejs and then proceeded to install nest through the @nest-cli command as recommended on their official website using my default bash terminal. My code editor of choice is V ...

Two separate occurrences hold identical values

I'm encountering an issue where instantiating a class two times results in the second instance retaining parameters from the first instance. Here's a simple example: var Test = function() {}; Test.prototype = { bonjour: null, hello: { h ...

Creating clickable links to MySQL data in Reactjs frontend

Required feature: The project names fetched from the MySQL database and displayed in a table column should serve as links leading to the corresponding information on the /projects page. Current status: Unfortunately, the project names extracted from the M ...