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

ali-api-gateway

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ali-api-gateway - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

55

index.js
'use strict';
const GateWay = require('./src/gate-way.js');
const getSSOInfo = require('./src/get-sso-info.js');
const co = require('co');
const parseParams = require('./src/parse-params.js');
const allowedCrossOrigin = require('./src/allowed-cross-origin.js');
const middlewares = {
getSSOInfo,
parseParams,
allowedCrossOrigin
const defaultOptions = {
parseParams: true
};
module.exports = {
GateWay,
middlewares
};
class ApiGateWay {
constructor(options) {
options = options || {};
this.options = Object.assign(defaultOptions, options);
this.middlewares = [];
if (this.options.parseParams) {
this.use(parseParams);
}
}
use(middleware) {
if (typeof middleware !== 'function') {
throw new Error('middleware must be function');
}
this.middlewares.push(middleware);
}
wrap() {
var middlewares = this.middlewares;
return function(event, context, callback) {
const ctx = {
event: event,
context: context,
result: {}
};
co(function *() {
var index = middlewares.length;
var prev = function *() {};
while (index--) {
prev = middlewares[index].bind(ctx, prev);
}
yield prev();
return callback(null, ctx.result);
}).catch(err => {
return callback(err, {});
});
};
}
}
module.exports = ApiGateWay;

2

package.json
{
"name": "ali-api-gateway",
"version": "0.0.2",
"version": "0.0.3",
"description": "proxy ali api gate way",

@@ -5,0 +5,0 @@ "main": "index.js",

README
======
为了更方便
'use strict';
const test = require('ava');
const apiGateWay = require('../');
const GateWay = apiGateWay.GateWay;
const ApiGateWay = require('../');
test.cb('middlewares run right', t => {
const apiGateWay = new GateWay();
const apiGateWay = new ApiGateWay({parseParams: false});
apiGateWay.use(function *(next) {

@@ -32,3 +31,3 @@ this.result = [];

test.cb('raw params in context and return result', t => {
const apiGateWay = new GateWay();
const apiGateWay = new ApiGateWay({parseParams: false});
apiGateWay.use(function *() {

@@ -51,3 +50,3 @@ this.result = {

test.cb('throw error', t => {
const apiGateWay = new GateWay();
const apiGateWay = new ApiGateWay({parseParams: false});
apiGateWay.use(function *() {

@@ -54,0 +53,0 @@ throw new Error('test');

'use strict';
const test = require('ava');
const apiGateWay = require('../');
const GateWay = apiGateWay.GateWay;
const middlewares = apiGateWay.middlewares;
const ApiGateWay = require('../');
test.cb('parse params success', t => {
const apiGateWay = new GateWay();
apiGateWay.use(middlewares.parseParams);
const apiGateWay = new ApiGateWay();
apiGateWay.use(function *() {

@@ -24,4 +21,3 @@ this.body = 'test';

test.cb('parse params success', t => {
const apiGateWay = new GateWay();
apiGateWay.use(middlewares.parseParams);
const apiGateWay = new ApiGateWay();
apiGateWay.use(function *() {

@@ -28,0 +24,0 @@ throw this.newError(400, 'error params');

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