Answers for "how to handle cors error in node js"

0

how to remove cors error from node app

app.use(function(req, res, next) {
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
    res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
    res.setHeader('Access-Control-Allow-Credentials', true);
    next();
});
Posted by: Guest on April-23-2021
1

express cors error

//install
npm install cors
//use
var express = require('express')
var cors = require('cors')
var app = express()

app.use(cors())

app.get('/products/:id', function (req, res, next) {
  res.json({msg: 'This is CORS-enabled for all origins!'})
})

app.listen(80, function () {
  console.log('CORS-enabled web server listening on port 80')
})
Posted by: Guest on September-20-2020

Code answers related to "how to handle cors error in node js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language