diff --git a/samples/DotnetIsolated-BidirectionChat/DotnetIsolated-BidirectionChat.csproj b/samples/DotnetIsolated-BidirectionChat/DotnetIsolated-BidirectionChat.csproj index fa777186..c6079ab4 100644 --- a/samples/DotnetIsolated-BidirectionChat/DotnetIsolated-BidirectionChat.csproj +++ b/samples/DotnetIsolated-BidirectionChat/DotnetIsolated-BidirectionChat.csproj @@ -1,15 +1,15 @@ - + - net6.0 + net8.0 v4 Exe IsolatedModel_BidirectionChat - - - - + + + + diff --git a/samples/DotnetIsolated-BidirectionChat/Functions.cs b/samples/DotnetIsolated-BidirectionChat/Functions.cs index 8b2c493c..5bafd021 100644 --- a/samples/DotnetIsolated-BidirectionChat/Functions.cs +++ b/samples/DotnetIsolated-BidirectionChat/Functions.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using System.Net; using Microsoft.Azure.Functions.Worker; @@ -19,7 +20,28 @@ public Functions(ILoggerFactory loggerFactory) public HttpResponseData GetWebPage([HttpTrigger(AuthorizationLevel.Anonymous)] HttpRequestData req) { var response = req.CreateResponse(HttpStatusCode.OK); - response.WriteString(File.ReadAllText("content/index.html")); + string content; + string home = Environment.GetEnvironmentVariable("HOME"); + if (!string.IsNullOrEmpty(home)) + { + string htmlFilePath = Path.Combine(home, "site", "wwwroot", "content", "index.html"); + if (File.Exists(htmlFilePath)) + { + // When running on Azure + content = File.ReadAllText(htmlFilePath); + } + else + { + // Assume the function is running locally with function core tools + content = File.ReadAllText("content/index.html"); + } + } + else + { + // Assume the function is running locally with function core tools + content = File.ReadAllText("content/index.html"); + } + response.WriteString(content); response.Headers.Add("Content-Type", "text/html"); return response; } diff --git a/samples/DotnetIsolated-BidirectionChat/content/index.html b/samples/DotnetIsolated-BidirectionChat/content/index.html index 1396df43..6711b787 100644 --- a/samples/DotnetIsolated-BidirectionChat/content/index.html +++ b/samples/DotnetIsolated-BidirectionChat/content/index.html @@ -165,9 +165,6 @@

Serverless chat

throw "No username entered"; } getConnectionInfo().then(info => { - // make compatible with old and new SignalRConnectionInfo - info.accessToken = info.AccessToken || info.accessKey; // pay attention to the case - info.url = info.Url || info.endpoint; // pay attention to the case data.ready = true; const options = { accessTokenFactory: () => info.accessToken diff --git a/samples/DotnetIsolated-ClassBased/Functions.cs b/samples/DotnetIsolated-ClassBased/Functions.cs index 57f0a6b9..f52b4ba9 100644 --- a/samples/DotnetIsolated-ClassBased/Functions.cs +++ b/samples/DotnetIsolated-ClassBased/Functions.cs @@ -22,13 +22,31 @@ public Functions(IServiceProvider serviceProvider, ILogger logger) : public HttpResponseData GetWebPage([HttpTrigger(AuthorizationLevel.Anonymous)] HttpRequestData req) { var response = req.CreateResponse(HttpStatusCode.OK); + string content; string home = Environment.GetEnvironmentVariable("HOME"); - string htmlFilePath = Path.Combine(home, "site", "wwwroot", "content", "index.html"); - response.WriteString(File.ReadAllText(htmlFilePath)); + if (!string.IsNullOrEmpty(home)) + { + string htmlFilePath = Path.Combine(home, "site", "wwwroot", "content", "index.html"); + if (File.Exists(htmlFilePath)) + { + // When running on Azure + content = File.ReadAllText(htmlFilePath); + } + else + { + // Assume the function is running locally with function core tools + content = File.ReadAllText("content/index.html"); + } + } + else + { + // Assume the function is running locally with function core tools + content = File.ReadAllText("content/index.html"); + } + response.WriteString(content); response.Headers.Add("Content-Type", "text/html"); return response; } - [Function("negotiate")] public async Task Negotiate([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestData req) {