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

Commit

Permalink
fix: Updates default http output binding (#308)
Browse files Browse the repository at this point in the history
This updates the default value for the name of the HTTP output binding from $return to $res to work around an issue that existing within the Azure core tools http runtime..

A bug exists in the Azure core tools http runtime that evaluates $return binding incorrectly which causes serialization issues when returning arrays within an HTTP response.
Azure/azure-functions-nodejs-worker#228
  • Loading branch information
wbreza authored and tbarlow12 committed Sep 13, 2019
1 parent 773e492 commit e7473a1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/services/azureKeyVaultService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Serverless from "serverless";
import { BaseService } from "./baseService";
import { FunctionAppService } from "./functionAppService";
import { KeyVaultManagementClient } from "@azure/arm-keyvault";
import { KeyPermissions, SecretPermissions, Vault } from "@azure/arm-keyvault/esm/models/index";
import { Vault, SecretPermissions } from "@azure/arm-keyvault/esm/models";

/**
* Defines the Azure Key Vault configuration
Expand Down
47 changes: 47 additions & 0 deletions src/shared/binding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,51 @@ describe("Bindings", () => {
BindingUtils.getBindingsMetaData(sls);
expect(sls.cli.log).toBeCalledWith("Parsing Azure Functions Bindings.json...");
});

it("Http output bindings should default to 'res'", () => {
const binding = BindingUtils.getHttpOutBinding();

expect(binding).toMatchObject({
type: "http",
direction: "out",
name: "res"
});
});

it("Gets the http binding with default settings", () => {
const serverless = MockFactory.createTestServerless();
const parsedBindings = BindingUtils.getBindingsMetaData(serverless);
const bindingType = "http";

const bindingTypes = parsedBindings.bindingTypes;
const bindingTypeIndex = bindingTypes.indexOf(bindingType);
const bindingSettings = parsedBindings.bindingSettings[bindingTypeIndex];

const binding = BindingUtils.getBinding(bindingType, bindingSettings, {});

expect(binding).toMatchObject({
type: "http",
direction: "out",
name: "res",
});
});

it("Gets the http binding with custom name", () => {
const serverless = MockFactory.createTestServerless();
const parsedBindings = BindingUtils.getBindingsMetaData(serverless);
const bindingType = "http";
const userSettings = { name: "custom" };

const bindingTypes = parsedBindings.bindingTypes;
const bindingTypeIndex = bindingTypes.indexOf(bindingType);
const bindingSettings = parsedBindings.bindingSettings[bindingTypeIndex];

const binding = BindingUtils.getBinding(bindingType, bindingSettings, userSettings);

expect(binding).toMatchObject({
type: "http",
direction: "out",
name: userSettings.name,
});
});
});
7 changes: 2 additions & 5 deletions src/shared/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,12 @@ export class BindingUtils {
return bindingUserSettingsMetaData;
}

public static getHttpOutBinding(bindingUserSettings) {
public static getHttpOutBinding() {
const binding = {};

binding[constants.type] = "http";
binding[constants.direction] = constants.outDirection;
binding[constants.name] = "$return";
if (bindingUserSettings[constants.webHookType]) {
binding[constants.name] = "res";
}
binding[constants.name] = "res";

return binding;
}
Expand Down
2 changes: 1 addition & 1 deletion src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class Utils {
}

if (bindingType === constants.httpTrigger) {
bindings.push(BindingUtils.getHttpOutBinding(bindingUserSettings));
bindings.push(BindingUtils.getHttpOutBinding());
}

functionsJson.bindings = bindings;
Expand Down

0 comments on commit e7473a1

Please sign in to comment.