Reputation: 11
I added the Headers to allow the http Delete, But When i try to delete(click the button) i have the following error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:5500/method. (Reason: missing token access-control-allow-origin in CORS header Access-Control-Allow-Headers from CORS preflight channel
let allowDelete = function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
next();
}
//And
router.options('/method', allowDelete);
router.delete('/method', functionT);
The request is like follow:
method(paramether: Paramether) {
return new Promise<boolean>( (resolve, reject) => {
this._http.delete<boolean>(Url, Option).subscribe( (res => {
resolve(res);
}));
});
}
Do you know where the problem is?
Upvotes: 0
Views: 1160
Reputation: 443
You need install: npm install cors , after install, import into app.js nodejs var cors = require('cors');
You can seen: Create Form Register using Nodejs + Vuejs
Upvotes: -1