azure-function-express
Advanced tools
Comparing version 1.2.2 to 1.3.0
@@ -5,2 +5,5 @@ "use strict"; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; /* eslint-disable no-underscore-dangle */ | ||
var _events = require("events"); | ||
@@ -16,5 +19,4 @@ | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /* eslint-disable no-underscore-dangle */ | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var NOOP = function NOOP() {}; | ||
@@ -29,3 +31,3 @@ | ||
* | ||
* @param {Object} context Azure context object for a single HTTP request. | ||
* @param {Object} context Raw Azure context object for a single HTTP request | ||
* @returns {object} Connection object | ||
@@ -35,2 +37,3 @@ */ | ||
var req = context.bindings.req; | ||
var xForwardedFor = req.headers ? req.headers["x-forwarded-for"] : undefined; | ||
@@ -45,2 +48,24 @@ | ||
/** | ||
* Copy usefull context properties from the native context provided by the Azure Function engine | ||
* | ||
* See: | ||
* - https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-node#context-object | ||
* - https://github.com/christopheranderson/azure-functions-typescript/blob/master/src/context.d.ts | ||
* | ||
* @param {Object} context Raw Azure context object for a single HTTP request | ||
* @returns {Object} Filtered context | ||
*/ | ||
function sanitizeContext(context) { | ||
var sanitizedContext = _extends({}, context, { | ||
log: context.log.bind(context) | ||
}); | ||
// We don't want the developper to mess up express flow | ||
// See https://github.com/yvele/azure-function-express/pull/12#issuecomment-336733540 | ||
delete sanitizedContext.done; | ||
return sanitizedContext; | ||
} | ||
/** | ||
* Request object wrapper | ||
@@ -55,5 +80,5 @@ * | ||
/** | ||
* Note: IncomingMessage assumes that all HTTP in is binded to "req" property. | ||
* Note: IncomingMessage assumes that all HTTP in is binded to "req" property | ||
* | ||
* @param {Object} context Azure context object for a single HTTP request. | ||
* @param {Object} context Sanitized Azure context object for a single HTTP request | ||
*/ | ||
@@ -63,6 +88,5 @@ function IncomingMessage(context) { | ||
// Inherit | ||
var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); | ||
Object.assign(_this, context.bindings.req); | ||
Object.assign(_this, context.bindings.req); // Inherit | ||
@@ -77,7 +101,3 @@ _this.url = _this.originalUrl; | ||
// Add access specific objects via req.context | ||
_this.context = { | ||
log: context.log.bind(context), | ||
invocationId: context.invocationId | ||
}; | ||
_this.context = sanitizeContext(context); // Specific to Azure Function | ||
return _this; | ||
@@ -84,0 +104,0 @@ } |
@@ -5,2 +5,5 @@ "use strict"; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /* eslint-disable no-magic-numbers, no-underscore-dangle */ | ||
var _statusCodes = require("./statusCodes"); | ||
@@ -12,5 +15,4 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /* eslint-disable no-magic-numbers, no-underscore-dangle */ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/** | ||
@@ -62,5 +64,12 @@ * @param {Object|string|Buffer} body Express/connect body object | ||
// 2. Status message | ||
this.statusMessage = statusMessage || _statusCodes2.default[statusCode] || "unknown"; | ||
if (typeof statusMessage === "string") { | ||
this.statusMessage = statusMessage; | ||
} else { | ||
this.statusMessage = _statusCodes2.default[statusCode] || "unknown"; | ||
} | ||
// 3. Headers | ||
if ((typeof statusMessage === "undefined" ? "undefined" : _typeof(statusMessage)) === "object" && typeof headers === "undefined") { | ||
headers = statusMessage; // eslint-disable-line no-param-reassign | ||
} | ||
if (this._headers) { | ||
@@ -67,0 +76,0 @@ // Slow-case: when progressive API and header fields are passed. |
{ | ||
"name": "azure-function-express", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "Allows Express usage with Azure Function", | ||
@@ -46,17 +46,18 @@ "keywords": [ | ||
"node": ">=6.5.0 <7", | ||
"npm": ">=4.1.2" | ||
"npm": ">=3" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.24.1", | ||
"babel-eslint": "^7.2.3", | ||
"babel-cli": "^6.26.0", | ||
"babel-eslint": "^8.0.1", | ||
"babel-plugin-add-module-exports": "^0.2.1", | ||
"babel-plugin-transform-export-extensions": "^6.22.0", | ||
"babel-preset-env": "^1.4.0", | ||
"babel-register": "^6.24.1", | ||
"eslint": "^3.19.0", | ||
"eslint-config-airbnb-base": "^11.1.3", | ||
"eslint-plugin-import": "^2.2.0", | ||
"express": "^4.15.2", | ||
"jest": "^19.0.2" | ||
"babel-plugin-transform-object-rest-spread": "~6.26.0", | ||
"babel-preset-env": "^1.6.0", | ||
"babel-register": "^6.26.0", | ||
"eslint": "^4.9.0", | ||
"eslint-config-airbnb-base": "^12.0.2", | ||
"eslint-plugin-import": "^2.7.0", | ||
"express": "^4.16.2", | ||
"jest": "^21.2.1" | ||
} | ||
} |
@@ -8,2 +8,3 @@ # azure-function-express | ||
[![npm version](https://img.shields.io/npm/v/azure-function-express.svg)](https://www.npmjs.com/package/azure-function-express) | ||
[![Node](https://img.shields.io/badge/node-v6.5.0-blue.svg)](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-node#node-version-and-package-management) | ||
[![Travis Status](https://img.shields.io/travis/yvele/azure-function-express/master.svg?label=travis)](https://travis-ci.org/yvele/azure-function-express) | ||
@@ -10,0 +11,0 @@ [![Coverage Status](https://img.shields.io/codecov/c/github/yvele/azure-function-express/master.svg)](https://codecov.io/github/yvele/azure-function-express) |
32114
10
372
92
12