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

Commit e7473a1

Browse files
wbrezatbarlow12
authored andcommitted
fix: Updates default http output binding (#308)
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
1 parent 773e492 commit e7473a1

File tree

4 files changed

+51
-7
lines changed

4 files changed

+51
-7
lines changed

src/services/azureKeyVaultService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Serverless from "serverless";
22
import { BaseService } from "./baseService";
33
import { FunctionAppService } from "./functionAppService";
44
import { KeyVaultManagementClient } from "@azure/arm-keyvault";
5-
import { KeyPermissions, SecretPermissions, Vault } from "@azure/arm-keyvault/esm/models/index";
5+
import { Vault, SecretPermissions } from "@azure/arm-keyvault/esm/models";
66

77
/**
88
* Defines the Azure Key Vault configuration

src/shared/binding.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,51 @@ describe("Bindings", () => {
2121
BindingUtils.getBindingsMetaData(sls);
2222
expect(sls.cli.log).toBeCalledWith("Parsing Azure Functions Bindings.json...");
2323
});
24+
25+
it("Http output bindings should default to 'res'", () => {
26+
const binding = BindingUtils.getHttpOutBinding();
27+
28+
expect(binding).toMatchObject({
29+
type: "http",
30+
direction: "out",
31+
name: "res"
32+
});
33+
});
34+
35+
it("Gets the http binding with default settings", () => {
36+
const serverless = MockFactory.createTestServerless();
37+
const parsedBindings = BindingUtils.getBindingsMetaData(serverless);
38+
const bindingType = "http";
39+
40+
const bindingTypes = parsedBindings.bindingTypes;
41+
const bindingTypeIndex = bindingTypes.indexOf(bindingType);
42+
const bindingSettings = parsedBindings.bindingSettings[bindingTypeIndex];
43+
44+
const binding = BindingUtils.getBinding(bindingType, bindingSettings, {});
45+
46+
expect(binding).toMatchObject({
47+
type: "http",
48+
direction: "out",
49+
name: "res",
50+
});
51+
});
52+
53+
it("Gets the http binding with custom name", () => {
54+
const serverless = MockFactory.createTestServerless();
55+
const parsedBindings = BindingUtils.getBindingsMetaData(serverless);
56+
const bindingType = "http";
57+
const userSettings = { name: "custom" };
58+
59+
const bindingTypes = parsedBindings.bindingTypes;
60+
const bindingTypeIndex = bindingTypes.indexOf(bindingType);
61+
const bindingSettings = parsedBindings.bindingSettings[bindingTypeIndex];
62+
63+
const binding = BindingUtils.getBinding(bindingType, bindingSettings, userSettings);
64+
65+
expect(binding).toMatchObject({
66+
type: "http",
67+
direction: "out",
68+
name: userSettings.name,
69+
});
70+
});
2471
});

src/shared/bindings.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,12 @@ export class BindingUtils {
5757
return bindingUserSettingsMetaData;
5858
}
5959

60-
public static getHttpOutBinding(bindingUserSettings) {
60+
public static getHttpOutBinding() {
6161
const binding = {};
6262

6363
binding[constants.type] = "http";
6464
binding[constants.direction] = constants.outDirection;
65-
binding[constants.name] = "$return";
66-
if (bindingUserSettings[constants.webHookType]) {
67-
binding[constants.name] = "res";
68-
}
65+
binding[constants.name] = "res";
6966

7067
return binding;
7168
}

src/shared/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class Utils {
7878
}
7979

8080
if (bindingType === constants.httpTrigger) {
81-
bindings.push(BindingUtils.getHttpOutBinding(bindingUserSettings));
81+
bindings.push(BindingUtils.getHttpOutBinding());
8282
}
8383

8484
functionsJson.bindings = bindings;

0 commit comments

Comments
 (0)