“CORS Masalah Node JS” Kode Jawaban

Ekspres 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

Kebijakan NodeJS CORS

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

CORS Masalah Node JS

//install package =>   npm i cros
const cors = require('cors');
const app = express()
app.use(cros()); // use this cros in middleware and done
CodePadding

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

CORS NPM

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')})
Disgusted Dotterel

Jawaban yang mirip dengan “CORS Masalah Node JS”

Pertanyaan yang mirip dengan “CORS Masalah Node JS”

Lebih banyak jawaban terkait untuk “CORS Masalah Node JS” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya