Skip to content
This repository has been archived by the owner on Apr 27, 2024. It is now read-only.

RedBulli/cors-tester

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cors-tester

cors-tester is used for testing CORS-request to a server. Makes a XHR request to a specified endpoint. Whole process takes about 2 seconds.

##Getting started ###Download cors-tester npm install cors-tester

###Using cors-tester

var corsTesterLib = require('cors-tester');
//Full return values, with errors and responses
corsTesterLib.makeCorsRequest('http://localhost:9000', function(returnValue) {
  console.log(returnValue);
});

//OR a very simplified response
corsTesterLib.simpleTest('http://localhost:9000', function(returnValue) {
  console.log(returnValue);
});

//These will make a GET request from Origin: http://localhost:4006 to the specified url
//Which means that the server should return proper Access-Control headers allowing http://localhost:4006 to access

// The first parameter can also be an object with the following variables
var config = {
  port: 4447, //Default=4006
  url: 'http://localhost:9000',
  method: 'POST' //Default="GET"
};
corsTesterLib.simpleTest(config, function(returnValue) {
  console.log(returnValue);
});

##How it works

  1. Setups a node.js http-server that serves a single html file
  2. The file is opened by Phantom.js browser with url-parameters
  3. The html contains a script that makes a XHR-request to an url specified in the url-parameters
  4. The application catches XHR-requests and responses and delivers them to the user

##Testing npm test

About

Testing CORS with PhantomJS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published