Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

To enable server-to-server and REST tools like Postman to access our API -

var whitelist = ['http://example.com']
var corsOptions = {
  origin: function (origin, callback) {
    if (whitelist.indexOf(origin) !== -1 || !origin) {
      callback(null, true)
    } else {
      callback(new Error('Not allowed by CORS'))
    }
  }
}

app.use(cors(corsOptions));
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #To #enable #REST #tools #Postman #access #API
ADD COMMENT
Topic
Name
9+2 =