-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#147) Web: add and enable a web project template
- Loading branch information
Showing
7 changed files
with
105 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace Emulsion.Web.Controllers | ||
|
||
open System | ||
open Microsoft.AspNetCore.Mvc | ||
open Microsoft.Extensions.Logging | ||
open Emulsion.Web | ||
|
||
[<ApiController>] | ||
[<Route("[controller]")>] | ||
type WeatherForecastController (logger : ILogger<WeatherForecastController>) = | ||
inherit ControllerBase() | ||
|
||
let summaries = | ||
[| | ||
"Freezing" | ||
"Bracing" | ||
"Chilly" | ||
"Cool" | ||
"Mild" | ||
"Warm" | ||
"Balmy" | ||
"Hot" | ||
"Sweltering" | ||
"Scorching" | ||
|] | ||
|
||
[<HttpGet>] | ||
member _.Get() = | ||
let rng = System.Random() | ||
[| | ||
for index in 0..4 -> | ||
{ Date = DateTime.Now.AddDays(float index) | ||
TemperatureC = rng.Next(-20,55) | ||
Summary = summaries.[rng.Next(summaries.Length)] } | ||
|] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
<PropertyGroup> | ||
<OutputType>Library</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="WeatherForecast.fs"/> | ||
<Compile Include="Controllers/WeatherForecastController.fs"/> | ||
<Compile Include="WebServer.fs"/> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Emulsion.Web | ||
|
||
open System | ||
|
||
type WeatherForecast = | ||
{ Date: DateTime | ||
TemperatureC: int | ||
Summary: string } | ||
|
||
member this.TemperatureF = | ||
32.0 + (float this.TemperatureC / 0.5556) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Emulsion.Web.WebServer | ||
|
||
open System | ||
open System.Threading.Tasks | ||
|
||
open Emulsion.Web.Controllers | ||
open Microsoft.AspNetCore.Builder | ||
open Microsoft.Extensions.DependencyInjection | ||
|
||
let run(baseUri: Uri): Task = | ||
// TODO: Pass baseUri | ||
let builder = WebApplication.CreateBuilder() | ||
builder.Services | ||
.AddControllers() | ||
.AddApplicationPart(typeof<WeatherForecastController>.Assembly) | ||
|> ignore | ||
|
||
let app = builder.Build() | ||
app.MapControllers() |> ignore | ||
app.RunAsync() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters