Skip to content

Commit

Permalink
Fix issue with default route prefix
Browse files Browse the repository at this point in the history
If the Azure Functions app used the default route prefix of api, but
that route prefix was NOT specified in host.json, the GetHostRoutePrefix
method would return null. This would break local debugging as the
ExecuteFunction implementation would try to invoke the wrong URI for
the target function. For example, it would try to invoke /Test rather
than /api/Test.

This PR fixes this issue by having GetHostRoutePrefix return 'api' in
the case where no route prefix is specified in host.json.

This change has been tested with four cases;

1. Default route prefix, no prefix specified in host.json.
2. Default route prefix, prefix specified in host.json.
3. Custom, non-empty route prefix, prefix specified in host.json.
4. Custom, empty route prefix, prefix specified in host.json.

Also update readme.md to call out that custom route prefixes require
changes to playfab.local.settings.json.
  • Loading branch information
MGudgin committed Mar 7, 2020
1 parent 7f13966 commit 739fbec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,19 @@ The above is supported in the following SDKs;

* [PlayFab C# SDK](https://github.com/PlayFab/CSharpSDK)
* [PlayFab Unity SDK](https://github.com/PlayFab/UnitySDK)
* [Unreal 4 Marketplace PlugIn for PlayFab](https://github.com/PlayFab/UnrealMarketplacePlugin)
* [Unreal 4 Marketplace PlugIn for PlayFab](https://github.com/PlayFab/UnrealMarketplacePlugin)

## Custom route prefixes

If you use a custom route prefix in your host.json, you will need to change the /api/ part of the file content to match the custom route prefix specified in the host.json. For example, if your host.json specifies a route prefix
of 'cs', then your playfab.local.settings.json should be as follows;

```
{ "LocalApiServer": "http://localhost:7071/cs/" }
```

If your host.json specifies an empty custom route prefix, then your playfab.local.settings.jsoon should be as follows;

```
{ "LocalApiServer": "http://localhost:7071/" }
```
4 changes: 2 additions & 2 deletions csharp/ExecuteFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static class LocalExecuteFunction
private const string DEV_SECRET_KEY = "PLAYFAB_DEV_SECRET_KEY";
private const string TITLE_ID = "PLAYFAB_TITLE_ID";
private const string CLOUD_NAME = "PLAYFAB_CLOUD_NAME";
private const string _defaultRoutePrefix = "api";
private static readonly HttpClient httpClient = new HttpClient();

/// <summary>
Expand Down Expand Up @@ -327,8 +328,7 @@ private static string GetHostRoutePrefix()
}

var hostModel = PlayFabSimpleJson.DeserializeObject<HostJsonModel>(hostFileContent);

return hostModel?.extensions?.http?.routePrefix;
return hostModel?.extensions?.http?.routePrefix ?? _defaultRoutePrefix;
}

private static async Task<string> DecompressHttpBody(HttpRequest request)
Expand Down

0 comments on commit 739fbec

Please sign in to comment.