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

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 :: remove and add active class with jquery 
Javascript :: react native view background transparency 
Javascript :: mui typography bold 
Javascript :: regex of date yyyy-mm-dd 
Javascript :: copy a file and paste with fs 
Javascript :: javascript float element right 
Javascript :: react js installation 
Javascript :: parse document.cookie 
Javascript :: how to refresh slick after tab function 
Javascript :: puppeteer get html 
Javascript :: math random equitative js 
Javascript :: get every member of a server discord js 
Javascript :: get text of selected option jquery 
Javascript :: javascript get random number in range 
Javascript :: Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) site:stackoverflow.com 
Javascript :: Remove line breaks with JavaScript 
Javascript :: sleep in react 
Javascript :: change format date javascript 
Javascript :: how to reset checkbox jquery 
Javascript :: jquery open a new tab 
Javascript :: best way to detect mobile device jquery 
Javascript :: jquery body class add 
Javascript :: js root url 
Javascript :: how to check if a string contains only spaces in javascript 
Javascript :: update node to latest version 
Javascript :: javascript remove last characters from string 
Javascript :: delete all children of div 
Javascript :: if media query jquery 
Javascript :: convert da decimale a hex javascript 
Javascript :: array of A-Z 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =