Skip to content

Commit 449379a

Browse files
committed
Addressing remaining http routing issues (#748).
1 parent be59bd0 commit 449379a

File tree

18 files changed

+422
-80
lines changed

18 files changed

+422
-80
lines changed

WebJobs.Script.sln

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ServiceBusTopicTrigger", "S
373373
sample\ServiceBusTopicTrigger\index.js = sample\ServiceBusTopicTrigger\index.js
374374
EndProjectSection
375375
EndProject
376-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HttpTrigger-CustomRoute", "HttpTrigger-CustomRoute", "{02FF2DFF-D7FA-4823-9E91-56C93FB2D447}"
376+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HttpTrigger-CustomRoute-Get", "HttpTrigger-CustomRoute-Get", "{02FF2DFF-D7FA-4823-9E91-56C93FB2D447}"
377377
ProjectSection(SolutionItems) = preProject
378-
sample\HttpTrigger-CustomRoute\function.json = sample\HttpTrigger-CustomRoute\function.json
379-
sample\HttpTrigger-CustomRoute\index.js = sample\HttpTrigger-CustomRoute\index.js
378+
sample\HttpTrigger-CustomRoute-Get\function.json = sample\HttpTrigger-CustomRoute-Get\function.json
379+
sample\HttpTrigger-CustomRoute-Get\index.js = sample\HttpTrigger-CustomRoute-Get\index.js
380380
EndProjectSection
381381
EndProject
382382
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HttpTrigger-CSharp-CustomRoute", "HttpTrigger-CSharp-CustomRoute", "{5957100B-2FAA-4D67-8CB3-C30D30FD92F8}"
@@ -385,6 +385,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HttpTrigger-CSharp-CustomRo
385385
sample\HttpTrigger-CSharp-CustomRoute\run.csx = sample\HttpTrigger-CSharp-CustomRoute\run.csx
386386
EndProjectSection
387387
EndProject
388+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HttpTrigger-CustomRoute-Post", "HttpTrigger-CustomRoute-Post", "{ADE3C399-6996-4677-89A8-60EDA27BF9C2}"
389+
ProjectSection(SolutionItems) = preProject
390+
sample\HttpTrigger-CustomRoute-Post\function.json = sample\HttpTrigger-CustomRoute-Post\function.json
391+
sample\HttpTrigger-CustomRoute-Post\index.js = sample\HttpTrigger-CustomRoute-Post\index.js
392+
EndProjectSection
393+
EndProject
388394
Global
389395
GlobalSection(SolutionConfigurationPlatforms) = preSolution
390396
Debug|Any CPU = Debug|Any CPU
@@ -485,5 +491,6 @@ Global
485491
{EE27035A-633D-48AE-BB86-597BBDBA706E} = {FF9C0818-30D3-437A-A62D-7A61CA44F459}
486492
{02FF2DFF-D7FA-4823-9E91-56C93FB2D447} = {FF9C0818-30D3-437A-A62D-7A61CA44F459}
487493
{5957100B-2FAA-4D67-8CB3-C30D30FD92F8} = {FF9C0818-30D3-437A-A62D-7A61CA44F459}
494+
{ADE3C399-6996-4677-89A8-60EDA27BF9C2} = {FF9C0818-30D3-437A-A62D-7A61CA44F459}
488495
EndGlobalSection
489496
EndGlobal

sample/HttpTrigger-CustomRoute/function.json renamed to sample/HttpTrigger-CustomRoute-Get/function.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "req",
66
"direction": "in",
77
"methods": [ "get" ],
8-
"route": "node/products/{category:alpha}/{id:int?}"
8+
"route": "node/products/{category:alpha}/{id:guid?}"
99
},
1010
{
1111
"type": "http",

sample/HttpTrigger-CustomRoute/index.js renamed to sample/HttpTrigger-CustomRoute-Get/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ module.exports = function (context, req) {
1515
// multiple products
1616
result = [
1717
{
18-
id: 123,
18+
id: '12ec126e-3208-4542-a4a0-30e65438832a',
1919
category: req.params.category
2020
},
2121
{
22-
id: 456,
22+
id: '4e2796ae-b865-4071-8a20-2a15cbaf856c',
2323
category: req.params.category
2424
}
2525
];
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"bindings": [
3+
{
4+
"type": "httpTrigger",
5+
"name": "req",
6+
"direction": "in",
7+
"methods": [ "post", "put" ],
8+
"route": "node/products/{category:alpha}/{id:guid}"
9+
},
10+
{
11+
"type": "http",
12+
"name": "$return",
13+
"direction": "out"
14+
},
15+
{
16+
"type": "blob",
17+
"name": "product",
18+
"direction": "out",
19+
"path": "samples-output/{category}/{id}"
20+
}
21+
]
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = function (context, req) {
2+
context.bindings.product = req.body;
3+
4+
var res = {
5+
status: 201,
6+
body: 'Product created'
7+
};
8+
9+
context.done(null, res);
10+
}
File renamed without changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"keys": [
3+
{
4+
"name": "default",
5+
"value": "5u3pyihh8ldfelipm3qdabw69iah0oghgzw8n959",
6+
"encrypted": false
7+
}
8+
]
9+
}

src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,9 @@
457457
<None Include="App_Data\secrets\host.json" />
458458
<Content Include="App_Data\secrets\httptrigger-powershell-modules.json" />
459459
<Content Include="App_Data\secrets\httptrigger-powershell.json" />
460-
<Content Include="App_Data\secrets\httptrigger-customroute.json" />
461460
<Content Include="App_Data\secrets\httptrigger-csharp-customroute.json" />
461+
<Content Include="App_Data\secrets\httptrigger-customroute-get.json" />
462+
<Content Include="App_Data\secrets\httptrigger-customroute-post.json" />
462463
<None Include="App_Data\secrets\HttpTrigger.json" />
463464
<Content Include="App_Data\secrets\webhook-azure-csharp.json" />
464465
<None Include="App_Data\secrets\WebHook-Generic-CSharp.json" />

src/WebJobs.Script.WebHost/WebScriptHostManager.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -417,18 +417,10 @@ internal void InitializeHttpFunctions(Collection<FunctionDescriptor> functions)
417417

418418
foreach (var function in functions)
419419
{
420-
HttpTriggerBindingMetadata httpTriggerBinding = (HttpTriggerBindingMetadata)function.Metadata.InputBindings.SingleOrDefault(p => string.Compare("HttpTrigger", p.Type, StringComparison.OrdinalIgnoreCase) == 0);
420+
var httpTriggerBinding = function.Metadata.InputBindings.OfType<HttpTriggerBindingMetadata>().SingleOrDefault();
421421
if (httpTriggerBinding != null)
422422
{
423-
string functionName = function.Metadata.Name;
424-
string route = httpTriggerBinding.Route;
425-
if (string.IsNullOrEmpty(route))
426-
{
427-
// if no explicit route is provided, default to the function name
428-
route = functionName;
429-
}
430-
431-
var httpRoute = httpRouteFactory.AddRoute(functionName, route, _httpRoutes);
423+
var httpRoute = httpRouteFactory.AddRoute(function.Metadata.Name, httpTriggerBinding.Route, httpTriggerBinding.Methods, _httpRoutes);
432424
_httpFunctions.Add(httpRoute, function);
433425
}
434426
}

src/WebJobs.Script/Binding/FunctionBinding.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,31 @@ protected FunctionBinding(ScriptHostConfiguration config, BindingMetadata metada
3535

3636
public abstract Collection<CustomAttributeBuilder> GetCustomAttributes(Type parameterType);
3737

38-
internal static Collection<FunctionBinding> GetBindings(ScriptHostConfiguration config, IEnumerable<BindingMetadata> bindingMetadatas, FileAccess fileAccess)
38+
internal static Collection<FunctionBinding> GetBindings(ScriptHostConfiguration config, IEnumerable<BindingMetadata> functions, FileAccess fileAccess)
3939
{
4040
Collection<FunctionBinding> bindings = new Collection<FunctionBinding>();
4141

4242
if (bindings != null)
4343
{
44-
foreach (var bindingMetadata in bindingMetadatas)
44+
foreach (var function in functions)
4545
{
46-
string type = bindingMetadata.Type.ToLowerInvariant();
46+
string type = function.Type.ToLowerInvariant();
4747
switch (type)
4848
{
4949
case "table":
50-
TableBindingMetadata tableBindingMetadata = (TableBindingMetadata)bindingMetadata;
50+
TableBindingMetadata tableBindingMetadata = (TableBindingMetadata)function;
5151
bindings.Add(new TableBinding(config, tableBindingMetadata, fileAccess));
5252
break;
5353
case "http":
5454
if (fileAccess != FileAccess.Write)
5555
{
5656
throw new InvalidOperationException("Http binding can only be used for output.");
5757
}
58-
bindings.Add(new HttpBinding(config, bindingMetadata, FileAccess.Write));
58+
bindings.Add(new HttpBinding(config, function, FileAccess.Write));
5959
break;
6060
default:
6161
FunctionBinding binding = null;
62-
if (TryParseFunctionBinding(config, bindingMetadata.Raw, out binding))
62+
if (TryParseFunctionBinding(config, function.Raw, out binding))
6363
{
6464
bindings.Add(binding);
6565
}

0 commit comments

Comments
 (0)