I have already set cors on the backend , I just dont know why I am receiving 404 error when the url is correct. The error is Access to XMLHttpRequest at 'http://localhost:3008/api/vehicle' from origin 'http://localhost:3007' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status. I have also added my api cross domain below. please check the sample code below.What would be the solution to this problem ? what causes this issues ?I have already set cors on the backend , I just dont know why I am receiving 404 error when the url is correct. The error is Access to XMLHttpRequest at 'http://localhost:3008/api/vehicle' from origin 'http://localhost:3007' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status. I have also added my api cross domain below. please check the sample code below.What would be the solution to this problem ? what causes this issues ?
Any idea?
Http post service
save(vehicle: Vehicle){
return this.http.post(
CONSTANST.routes.person.save,
{
Stock: vehicle.Stock,
VIN: vehicle.VIN,
age: vehicle.age,
gender: vehicle.gender,
},
);
}
routes
const HOST ='http://localhost:3008'
export const CONSTANST = {
permissions:{},
routes:{
authorization:{
login: HOST + '/api/app/signin-email',
logout: HOST + '/api/auth/logout'
},
person:{
list: HOST + '/api/vehicle',
save: HOST + '/api/vehicle',
},
user: {}
},
lang:{},
session:{},
parameters:{}
};
api cross domain request
if (process.env.NODE_ENV !== 'production') {
console.log('------------------------------------------------');
console.log('Notice: Enabling CORS for development.');
console.log('------------------------------------------------');
app.all('*', function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET, POST');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
});
}
api routes
app.get('/api/vehicle', keystone.middleware.api, routes.api.vehicle.list);
app.post('/api/vehicle', keystone.middleware.api ,routes.api.vehicle.create);
*
orhttp://localhost:3007
to bypass this – Nithin Kumar BiliyaHOST +
– Arif Khan