From 7dfab26fbfb5c883ef2a2bb04228660eec52eb6a Mon Sep 17 00:00:00 2001 From: Anthony Chu Date: Tue, 24 Nov 2020 23:40:13 -0800 Subject: [PATCH] Initial commit --- .gitignore | 43 ++++++++++++++++ .vscode/extensions.json | 5 ++ README.md | 4 ++ WeatherForecast/function.json | 19 +++++++ .../Controllers/WeatherForecastController.cs | 39 +++++++++++++++ handler/Program.cs | 26 ++++++++++ handler/Properties/launchSettings.json | 30 ++++++++++++ handler/Startup.cs | 49 +++++++++++++++++++ handler/WeatherForecast.cs | 15 ++++++ handler/appsettings.Development.json | 9 ++++ handler/handler.csproj | 8 +++ host.json | 26 ++++++++++ 12 files changed, 273 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 README.md create mode 100644 WeatherForecast/function.json create mode 100644 handler/Controllers/WeatherForecastController.cs create mode 100644 handler/Program.cs create mode 100644 handler/Properties/launchSettings.json create mode 100644 handler/Startup.cs create mode 100644 handler/WeatherForecast.cs create mode 100644 handler/appsettings.Development.json create mode 100644 handler/handler.csproj create mode 100644 host.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fbbe2ef --- /dev/null +++ b/.gitignore @@ -0,0 +1,43 @@ +bin +obj +csx +.vs +edge +Publish + +*.user +*.suo +*.cscfg +*.Cache +project.lock.json + +/packages +/TestResults + +/tools/NuGet.exe +/App_Data +/secrets +/data +.secrets +appsettings.json +local.settings.json + +node_modules +dist + +# Local python packages +.python_packages/ + +# Python Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..dde673d --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "ms-azuretools.vscode-azurefunctions" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f245517 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +```bash +dotnet publish handler/handler.csproj -o handler/publish +func start +``` \ No newline at end of file diff --git a/WeatherForecast/function.json b/WeatherForecast/function.json new file mode 100644 index 0000000..82c5ae7 --- /dev/null +++ b/WeatherForecast/function.json @@ -0,0 +1,19 @@ +{ + "bindings": [ + { + "authLevel": "function", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "get", + "post" + ] + }, + { + "type": "http", + "direction": "out", + "name": "res" + } + ] +} \ No newline at end of file diff --git a/handler/Controllers/WeatherForecastController.cs b/handler/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..8a48e0b --- /dev/null +++ b/handler/Controllers/WeatherForecastController.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +namespace handler.Controllers +{ + [ApiController] + [Route("api/[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public IEnumerable Get() + { + var rng = new Random(); + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/handler/Program.cs b/handler/Program.cs new file mode 100644 index 0000000..8c400c8 --- /dev/null +++ b/handler/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace handler +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/handler/Properties/launchSettings.json b/handler/Properties/launchSettings.json new file mode 100644 index 0000000..ea73413 --- /dev/null +++ b/handler/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:13066", + "sslPort": 44379 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "handler": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/handler/Startup.cs b/handler/Startup.cs new file mode 100644 index 0000000..02e3b9e --- /dev/null +++ b/handler/Startup.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace handler +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/handler/WeatherForecast.cs b/handler/WeatherForecast.cs new file mode 100644 index 0000000..0234f4f --- /dev/null +++ b/handler/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System; + +namespace handler +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string Summary { get; set; } + } +} diff --git a/handler/appsettings.Development.json b/handler/appsettings.Development.json new file mode 100644 index 0000000..dba68eb --- /dev/null +++ b/handler/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/handler/handler.csproj b/handler/handler.csproj new file mode 100644 index 0000000..400722f --- /dev/null +++ b/handler/handler.csproj @@ -0,0 +1,8 @@ + + + + netcoreapp3.1 + + + + diff --git a/host.json b/host.json new file mode 100644 index 0000000..c2fec37 --- /dev/null +++ b/host.json @@ -0,0 +1,26 @@ +{ + "version": "2.0", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + } + } + }, + "extensionBundle": { + "id": "Microsoft.Azure.Functions.ExtensionBundle", + "version": "[1.*, 2.0.0)" + }, + "customHandler": { + "description": { + "defaultExecutablePath": "dotnet", + "workingDirectory": "", + "arguments": [ + "handler/publish/handler.dll", + "--urls", "http://localhost:%FUNCTIONS_CUSTOMHANDLER_PORT%" + ] + }, + "enableForwardingHttpRequest": true + } +} \ No newline at end of file