Skip to content
/ FORS Public

Front-End-Only Cross-Origin Resource Sharing | 纯前端跨域功能实现

License

Notifications You must be signed in to change notification settings

DOLLOR/FORS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FORS

Front-end-Only Resource Sharing

USAGE

Set allowList in fors-proxy.html.

var allowList = ['https://localhost:8889', 'http://localhost:8888'];

var allowList = ['https://our.site.com', 'http://our.site.org'];

Put fors-proxy.html on their site.

Now request from our site:

fors.fRequest({
  proxy:'http://their.site:8888/path/to/fors-proxy.html?s='
    + encodeURIComponent('http://any.site/path/to/fors.js'),
  url:'/api/on/their/site.xml',
  headers:{testHeader:+new Date()},
  xhrProp:{timeout:15000},
},function(result){
  console.log(result);
});

API

/**
 * fRequest
 * @param {Object} option - request option
 * @param {String} option.proxy - fors-proxy.html file url
 * @param {Boolean} option.once - the iframe will be removed after request if true
 * @param {String} option.url - target url, from which you want to request data
 * @param {String} option.method - GET, POST, or one of  other methods
 * @param {Boolean} option.isAsync - this value will pass to xhr.open() async argument
 * @param {Object} option.data - request body
 * @param {Object} option.xhrProp - other props that will past to xhr object
 * @param {Object} option.headers - request headers
 * @param {(headers,response,responseText,responseType,responseURL,status,statusText)=>} callback - callback for result
 */

About

Front-End-Only Cross-Origin Resource Sharing | 纯前端跨域功能实现

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published