“NodeJS CORS -Richtlinie” Code-Antworten

Express JS CORS

var express = require('express')
var cors = require('cors')  //use this
var app = express()

app.use(cors()) //and this

app.get('/user/:id', function (req, res, next) {
  res.json({user: 'CORS enabled'})
})

app.listen(5000, function () {
  console.log('CORS-enabled web server listening on port 5000')
})
Batman

NodeJS CORS -Richtlinie

app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "YOUR-DOMAIN.TLD"); // update to match the domain you will make the request from
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});

app.get('/', function(req, res, next) {
  // Handle the get for this route
});

app.post('/', function(req, res, next) {
 // Handle the post for this route
});
Annoying Anteater

Ähnliche Antworten wie “NodeJS CORS -Richtlinie”

Fragen ähnlich wie “NodeJS CORS -Richtlinie”

Weitere verwandte Antworten zu “NodeJS CORS -Richtlinie” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen