Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

access-control-allow-origin nodejs express

// Add headers
app.use(function (req, res, next) {

    // Website you wish to allow to connect
    res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8888');

    // Request methods you wish to allow
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');

    // Request headers you wish to allow
    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');

    // Set to true if you need the website to include cookies in the requests sent
    // to the API (e.g. in case you use sessions)
    res.setHeader('Access-Control-Allow-Credentials', true);

    // Pass to next layer of middleware
    next();
});
Comment

allow cross origin node

app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});
Comment

access-control-allow-origin nodejs express


var express = require('express');
var app = express();
var Assessment = require('../app/models/assessment');

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

app.post('/api/status', function (req, res, next) {
    // your code goes here
});

module.exports = app;

Comment

add access-control-allow-origin in node js

// Install cors package: npm install cors
const express = require("express");
const app = express();
const cors = require('cors');
app.use(cors());
// your http request should work after this
Comment

add access-control-allow-origin in node js


// Add headers before the routes are defined
app.use(function (req, res, next) {

    // Website you wish to allow to connect
    res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8888');

    // Request methods you wish to allow
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');

    // Request headers you wish to allow
    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');

    // Set to true if you need the website to include cookies in the requests sent
    // to the API (e.g. in case you use sessions)
    res.setHeader('Access-Control-Allow-Credentials', true);

    // Pass to next layer of middleware
    next();
});

Comment

PREVIOUS NEXT
Code Example
Javascript :: mongoose custom object schema 
Javascript :: javascript json parse 
Javascript :: pauze js 
Javascript :: array of refs react 
Javascript :: npm for node types 
Javascript :: js get vh value 
Javascript :: react json object pretty 
Javascript :: nodejs request api 
Javascript :: open gz file node 
Javascript :: list from 1 to 100 js 
Javascript :: is_int js 
Javascript :: Error: Requires Babel "^7.0.0-0", but was loaded with "6.26.3". 
Javascript :: two decimel javascript 
Javascript :: node redisjson get properties of array object 
Javascript :: jquery append element to body 
Javascript :: props type 
Javascript :: sequelize sync 
Javascript :: window is not defined Next Js 
Javascript :: jquery summernote set value 
Javascript :: react array find index 
Javascript :: javascript sum array 
Javascript :: unable to open file in target xcode react native 
Javascript :: include jsp in another jsp 
Javascript :: javascript onclick open url same window 
Javascript :: prevent form submission on onsubmit function calls 
Javascript :: get current time epoch javascript 
Javascript :: localstorage remove item 
Javascript :: jest mock react-redux hooks 
Javascript :: javascript caesar cipher 
Javascript :: bootstrap icons react 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =