“Kesalahan CORS di Node JS Express” Kode Jawaban

Cors di Express

const cors = require('cors');

const corsOption = {
    origin: ['http://localhost:3000'],
};
app.use(cors(corsOption));
//if you want in every domain then
app.use(cors())
Shirshak kandel

Izinkan CORS Express

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();
});
Poised Penguin

Express CORS error

// CORS (Cross-Origin Resource Sharing) headers to support Cross-site HTTP requests

app.all('*', function(req, res, next) {
       res.header("Access-Control-Allow-Origin", "*");
       res.header("Access-Control-Allow-Headers", "X-Requested-With");
       res.header('Access-Control-Allow-Headers', 'Content-Type');
       next();
});
Zany Zebra

Ekspres JS Cors

//Cors = Cross-origin resource sharing

var express = require('express');
var cors = require('cors');
var app = express();

app.use(cors());

var corsOptions = {
  origin: 'http://example.com',
  optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
}

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

Kesalahan CORS di Node JS Express

var cors = require('cors')

var app = express()
app.use(cors())
Tamer Jarrar

Jawaban yang mirip dengan “Kesalahan CORS di Node JS Express”

Pertanyaan yang mirip dengan “Kesalahan CORS di Node JS Express”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya