From aeb359506ded9acb6354f806f76e9f98234c0043 Mon Sep 17 00:00:00 2001 From: Beau Findlay Date: Thu, 7 Mar 2024 22:22:32 +0000 Subject: [PATCH] Add Azure function app project with test function --- BeauFindlay/BeauFindlay.sln | 9 +- BeauFindlay/src/BeauFindlay.Api/.gitignore | 264 ++++++++++++++++++ .../BeauFindlay.Api/BeauFindlay.Api.csproj | 28 ++ BeauFindlay/src/BeauFindlay.Api/Function1.cs | 25 ++ BeauFindlay/src/BeauFindlay.Api/Program.cs | 14 + .../Properties/launchSettings.json | 9 + .../Properties/serviceDependencies.json | 11 + .../Properties/serviceDependencies.local.json | 11 + BeauFindlay/src/BeauFindlay.Api/host.json | 12 + .../BeauFindlay.Client/Pages/Contact.razor | 23 ++ BeauFindlay/src/BeauFindlay.Client/Program.cs | 7 +- .../staticwebapp.config.json | 5 + .../wwwroot/appsettings.json | 10 + 13 files changed, 425 insertions(+), 3 deletions(-) create mode 100644 BeauFindlay/src/BeauFindlay.Api/.gitignore create mode 100644 BeauFindlay/src/BeauFindlay.Api/BeauFindlay.Api.csproj create mode 100644 BeauFindlay/src/BeauFindlay.Api/Function1.cs create mode 100644 BeauFindlay/src/BeauFindlay.Api/Program.cs create mode 100644 BeauFindlay/src/BeauFindlay.Api/Properties/launchSettings.json create mode 100644 BeauFindlay/src/BeauFindlay.Api/Properties/serviceDependencies.json create mode 100644 BeauFindlay/src/BeauFindlay.Api/Properties/serviceDependencies.local.json create mode 100644 BeauFindlay/src/BeauFindlay.Api/host.json create mode 100644 BeauFindlay/src/BeauFindlay.Client/Pages/Contact.razor create mode 100644 BeauFindlay/src/BeauFindlay.Client/staticwebapp.config.json create mode 100644 BeauFindlay/src/BeauFindlay.Client/wwwroot/appsettings.json diff --git a/BeauFindlay/BeauFindlay.sln b/BeauFindlay/BeauFindlay.sln index 737e844..0e7661a 100644 --- a/BeauFindlay/BeauFindlay.sln +++ b/BeauFindlay/BeauFindlay.sln @@ -5,7 +5,9 @@ VisualStudioVersion = 17.9.34622.214 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3407557D-A21B-4F48-930C-6FDCE961ED2A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeauFindlay.Client", "src\BeauFindlay.Client\BeauFindlay.Client.csproj", "{979CCAA2-5F1B-457B-9536-02F94BC98F9F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeauFindlay.Client", "src\BeauFindlay.Client\BeauFindlay.Client.csproj", "{979CCAA2-5F1B-457B-9536-02F94BC98F9F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeauFindlay.Api", "src\BeauFindlay.Api\BeauFindlay.Api.csproj", "{D2F248BF-8487-4CE7-B6AA-D558587A52DA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -17,12 +19,17 @@ Global {979CCAA2-5F1B-457B-9536-02F94BC98F9F}.Debug|Any CPU.Build.0 = Debug|Any CPU {979CCAA2-5F1B-457B-9536-02F94BC98F9F}.Release|Any CPU.ActiveCfg = Release|Any CPU {979CCAA2-5F1B-457B-9536-02F94BC98F9F}.Release|Any CPU.Build.0 = Release|Any CPU + {D2F248BF-8487-4CE7-B6AA-D558587A52DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D2F248BF-8487-4CE7-B6AA-D558587A52DA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D2F248BF-8487-4CE7-B6AA-D558587A52DA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D2F248BF-8487-4CE7-B6AA-D558587A52DA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {979CCAA2-5F1B-457B-9536-02F94BC98F9F} = {3407557D-A21B-4F48-930C-6FDCE961ED2A} + {D2F248BF-8487-4CE7-B6AA-D558587A52DA} = {3407557D-A21B-4F48-930C-6FDCE961ED2A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {6D05FF39-4D7B-4F0D-8136-E48F71106C3A} diff --git a/BeauFindlay/src/BeauFindlay.Api/.gitignore b/BeauFindlay/src/BeauFindlay.Api/.gitignore new file mode 100644 index 0000000..ff5b00c --- /dev/null +++ b/BeauFindlay/src/BeauFindlay.Api/.gitignore @@ -0,0 +1,264 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# Azure Functions localsettings file +local.settings.json + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +#*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc \ No newline at end of file diff --git a/BeauFindlay/src/BeauFindlay.Api/BeauFindlay.Api.csproj b/BeauFindlay/src/BeauFindlay.Api/BeauFindlay.Api.csproj new file mode 100644 index 0000000..9da3f88 --- /dev/null +++ b/BeauFindlay/src/BeauFindlay.Api/BeauFindlay.Api.csproj @@ -0,0 +1,28 @@ + + + net8.0 + v4 + Exe + enable + enable + + + + + + + + + + + PreserveNewest + + + PreserveNewest + Never + + + + + + \ No newline at end of file diff --git a/BeauFindlay/src/BeauFindlay.Api/Function1.cs b/BeauFindlay/src/BeauFindlay.Api/Function1.cs new file mode 100644 index 0000000..9260290 --- /dev/null +++ b/BeauFindlay/src/BeauFindlay.Api/Function1.cs @@ -0,0 +1,25 @@ +using System.Net; +using Microsoft.Azure.Functions.Worker; +using Microsoft.Azure.Functions.Worker.Http; +using Microsoft.Extensions.Logging; + +namespace BeauFindlay.Api +{ + public class Function1(ILoggerFactory loggerFactory) + { + private readonly ILogger _logger = loggerFactory.CreateLogger(); + + [Function("Function1")] + public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req) + { + _logger.LogInformation("C# HTTP trigger function processed a request."); + + var response = req.CreateResponse(HttpStatusCode.OK); + response.Headers.Add("Content-Type", "text/plain; charset=utf-8"); + + response.WriteString("Welcome to Azure Functions!"); + + return response; + } + } +} diff --git a/BeauFindlay/src/BeauFindlay.Api/Program.cs b/BeauFindlay/src/BeauFindlay.Api/Program.cs new file mode 100644 index 0000000..9de3b3e --- /dev/null +++ b/BeauFindlay/src/BeauFindlay.Api/Program.cs @@ -0,0 +1,14 @@ +using Microsoft.Azure.Functions.Worker; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +var host = new HostBuilder() + .ConfigureFunctionsWorkerDefaults() + .ConfigureServices(services => + { + services.AddApplicationInsightsTelemetryWorkerService(); + services.ConfigureFunctionsApplicationInsights(); + }) + .Build(); + +host.Run(); diff --git a/BeauFindlay/src/BeauFindlay.Api/Properties/launchSettings.json b/BeauFindlay/src/BeauFindlay.Api/Properties/launchSettings.json new file mode 100644 index 0000000..e296acb --- /dev/null +++ b/BeauFindlay/src/BeauFindlay.Api/Properties/launchSettings.json @@ -0,0 +1,9 @@ +{ + "profiles": { + "BeauFindlay.Api": { + "commandName": "Project", + "commandLineArgs": "--port 7197", + "launchBrowser": false + } + } +} \ No newline at end of file diff --git a/BeauFindlay/src/BeauFindlay.Api/Properties/serviceDependencies.json b/BeauFindlay/src/BeauFindlay.Api/Properties/serviceDependencies.json new file mode 100644 index 0000000..df4dcc9 --- /dev/null +++ b/BeauFindlay/src/BeauFindlay.Api/Properties/serviceDependencies.json @@ -0,0 +1,11 @@ +{ + "dependencies": { + "appInsights1": { + "type": "appInsights" + }, + "storage1": { + "type": "storage", + "connectionId": "AzureWebJobsStorage" + } + } +} \ No newline at end of file diff --git a/BeauFindlay/src/BeauFindlay.Api/Properties/serviceDependencies.local.json b/BeauFindlay/src/BeauFindlay.Api/Properties/serviceDependencies.local.json new file mode 100644 index 0000000..b804a28 --- /dev/null +++ b/BeauFindlay/src/BeauFindlay.Api/Properties/serviceDependencies.local.json @@ -0,0 +1,11 @@ +{ + "dependencies": { + "appInsights1": { + "type": "appInsights.sdk" + }, + "storage1": { + "type": "storage.emulator", + "connectionId": "AzureWebJobsStorage" + } + } +} \ No newline at end of file diff --git a/BeauFindlay/src/BeauFindlay.Api/host.json b/BeauFindlay/src/BeauFindlay.Api/host.json new file mode 100644 index 0000000..ee5cf5f --- /dev/null +++ b/BeauFindlay/src/BeauFindlay.Api/host.json @@ -0,0 +1,12 @@ +{ + "version": "2.0", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + }, + "enableLiveMetricsFilters": true + } + } +} \ No newline at end of file diff --git a/BeauFindlay/src/BeauFindlay.Client/Pages/Contact.razor b/BeauFindlay/src/BeauFindlay.Client/Pages/Contact.razor new file mode 100644 index 0000000..0705478 --- /dev/null +++ b/BeauFindlay/src/BeauFindlay.Client/Pages/Contact.razor @@ -0,0 +1,23 @@ +@page "/contact" + +@inject HttpClient HttpClient + +@if (!string.IsNullOrWhiteSpace(apiResponse)) +{ +

Response from Azure Function API: @apiResponse

+} + +@code { + private string apiResponse = ""; + + protected override async Task OnInitializedAsync() + { + var response = await HttpClient.GetStringAsync("/api/Function1"); + + if (!string.IsNullOrWhiteSpace(response)) + { + apiResponse = response; + } + } + +} \ No newline at end of file diff --git a/BeauFindlay/src/BeauFindlay.Client/Program.cs b/BeauFindlay/src/BeauFindlay.Client/Program.cs index 0cc5805..6f15f4e 100644 --- a/BeauFindlay/src/BeauFindlay.Client/Program.cs +++ b/BeauFindlay/src/BeauFindlay.Client/Program.cs @@ -7,8 +7,11 @@ var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("#app"); builder.RootComponents.Add("head::after"); -builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); +var apiBase = builder.Configuration["ApiBase"] + ?? throw new ArgumentException("API base address not found in config."); + +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(apiBase) }); builder.Services.AddSingleton(); -await builder.Build().RunAsync(); +await builder.Build().RunAsync(); \ No newline at end of file diff --git a/BeauFindlay/src/BeauFindlay.Client/staticwebapp.config.json b/BeauFindlay/src/BeauFindlay.Client/staticwebapp.config.json new file mode 100644 index 0000000..1d186ee --- /dev/null +++ b/BeauFindlay/src/BeauFindlay.Client/staticwebapp.config.json @@ -0,0 +1,5 @@ +{ + "navigationFallback": { + "rewrite": "/index.html" + } +} \ No newline at end of file diff --git a/BeauFindlay/src/BeauFindlay.Client/wwwroot/appsettings.json b/BeauFindlay/src/BeauFindlay.Client/wwwroot/appsettings.json new file mode 100644 index 0000000..25e6abd --- /dev/null +++ b/BeauFindlay/src/BeauFindlay.Client/wwwroot/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "ApiBase": "http://localhost:7071" +} \ No newline at end of file