Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ekit-cross-site

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ekit-cross-site

ekit package, support cross site manager

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

ekit-cross-site

Problem

You may face the problem with Access-Control-Allow-Origin when you want to call API on cross domain. Here is the simple solution for that.

Usage

Require ekit-cross-site module before all other API defination and put the list of allow site as below

Note: only use with expressjs

...
var app = express();

app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  ...
});

require('ekit-cross-site')(app, ['http://127.0.0.1:9000', 'http://0.0.0.0:9000']);
...

How does it look like

var config = {
	allow: ['http://127.0.0.1:9000', 'http://0.0.0.0:9000']
};

module.exports = function(app, allowList) {
	// allow
	config.allow = allowList;
	// allow request
	app.all('/*', function(req, res, next) {
		var isPass = false;
		for (var i in config.allow) {
			if (req.headers.origin === config.allow[i]) {
				isPass = true;
			}
		};
		if (isPass === true) {
			res.header('Access-Control-Allow-Origin', req.headers.origin);
			res.header('Access-Control-Allow-Methods', '*');
			res.header('Access-Control-Allow-Headers', 'Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept');
		};
		return next();
	});
}

Keywords

FAQs

Package last updated on 13 Nov 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc