Answers for "js cors"

26

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')
})
Posted by: Guest on November-13-2020
-1

cross origin even with allow header

header('Access-Control-Allow-Origin: http://localhost:8100');
header ("Access-Control-Expose-Headers: Content-Length, X-JSON");
header ("Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS");
header ("Access-Control-Allow-Headers: Content-Type, Authorization, Accept, Accept-Language, X-Authorization");
header('Access-Control-Max-Age: 86400');

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    // The request is using the POST method
    header("HTTP/1.1 200 OK");
    return;

}
Posted by: Guest on July-12-2020
0

cors in javascript

Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that 
allows a server to indicate any other origins (domain, scheme, or port) than 
its own from which a browser should permit loading of resources. CORS also 
relies on a mechanism by which browsers make a “preflight” request to the 
server hosting the cross-origin resource, in order to check that the server 
will permit the actual request. In that preflight, the browser sends headers 
that indicate the HTTP method and headers that will be used in the actual 
request.
Posted by: Guest on June-06-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language