Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinmoris committed Apr 13, 2020
2 parents 41d6c43 + 879bd16 commit 612aa18
Show file tree
Hide file tree
Showing 21 changed files with 199 additions and 91 deletions.
86 changes: 52 additions & 34 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,13 @@ Sometimes an `HttpHandler` wants to return early and not continue with the remai
A typical example would be an authentication or authorization handler, which would not continue with the remaining pipeline if a user wasn't authenticated. Instead it might want to return a `401 Unauthorized` response:

```fsharp
let finishEarly : HttpFunc = Some >> Task.FromResult
let earlyReturn : HttpFunc = Some >> Task.FromResult
let checkUserIsLoggedIn : HttpHandler =
fun (next : HttpFunc) (ctx : HttpContext) ->
if isNotNull ctx.User && ctx.User.Identity.IsAuthenticated
then next ctx
else (setStatusCode 401 >=> text "Please sign in.") finishEarly ctx
else setStatusCode 401 earlyReturn ctx
```

In the `else` clause the `checkUserIsLoggedIn` handler returns a `401 Unauthorized` HTTP response and skips the remaining `HttpHandler` pipeline by not invoking `next` but an already completed task.
Expand Down Expand Up @@ -399,9 +399,12 @@ type Startup() =
[<EntryPoint>]
let main _ =
WebHostBuilder()
.UseKestrel()
.UseStartup<Startup>()
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(
fun webHostBuilder ->
webHostBuilder
.UseStartup<Startup>()
|> ignore)
.Build()
.Run()
0
Expand All @@ -427,10 +430,13 @@ let configureServices (services : IServiceCollection) =
[<EntryPoint>]
let main _ =
WebHostBuilder()
.UseKestrel()
.Configure(Action<IApplicationBuilder> configureApp)
.ConfigureServices(configureServices)
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(
fun webHostBuilder ->
webHostBuilder
.Configure(configureApp)
.ConfigureServices(configureServices)
|> ignore)
.Build()
.Run()
0
Expand All @@ -454,12 +460,15 @@ let configureServices (services : IServiceCollection) =
[<EntryPoint>]
let main _ =
WebHostBuilder()
.UseKestrel()
.Configure(Action<IApplicationBuilder> configureApp)
// Calling ConfigureServices to set up dependencies
.ConfigureServices(configureServices)
.ConfigureLogging(configureLogging)
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(
fun webHostBuilder ->
webHostBuilder
.Configure(configureApp)
// Calling ConfigureServices to set up dependencies
.ConfigureServices(configureServices)
.ConfigureLogging(configureLogging)
|> ignore)
.Build()
.Run()
0
Expand Down Expand Up @@ -548,12 +557,15 @@ let configureLogging (builder : ILoggingBuilder) =
[<EntryPoint>]
let main _ =
WebHostBuilder()
.UseKestrel()
.Configure(Action<IApplicationBuilder> configureApp)
.ConfigureServices(configureServices)
// Calling ConfigureLogging to set up logging providers
.ConfigureLogging(configureLogging)
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(
fun webHostBuilder ->
webHostBuilder
.Configure(configureApp)
.ConfigureServices(configureServices)
// Calling ConfigureLogging to set up logging providers
.ConfigureLogging(configureLogging)
|> ignore)
.Build()
.Run()
0
Expand Down Expand Up @@ -622,12 +634,15 @@ let configureApp (app : IApplicationBuilder) =
[<EntryPoint>]
let main _ =
WebHostBuilder()
.UseKestrel()
// Calling Configure to set up all middleware
.Configure(Action<IApplicationBuilder> configureApp)
.ConfigureServices(configureServices)
.ConfigureLogging(configureLogging)
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(
fun webHostBuilder ->
webHostBuilder
// Calling Configure to set up all middleware
.Configure(configureApp)
.ConfigureServices(configureServices)
.ConfigureLogging(configureLogging)
|> ignore)
.Build()
.Run()
0
Expand All @@ -649,9 +664,12 @@ type Startup() =
[<EntryPoint>]
let main _ =
WebHostBuilder()
.UseKestrel()
.UseStartup<Startup>()
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(
fun webHostBuilder ->
webHostBuilder
.UseStartup<Startup>()
|> ignore)
.Build()
.Run()
0
Expand Down Expand Up @@ -3008,12 +3026,12 @@ It is possible to add JavaScript event handlers to HTML elements using the Giraf
This example illustrates how inline JavaScript could be used to log to the console when a button is clicked:

```fsharp
let inlineJSButton =
let inlineJSButton =
button [_id "inline-js"
_onclick "console.log(\"Hello from the 'inline-js' button!\");"] [str "Say Hello" ]
```

There are some caveats with this approach, namely that
There are some caveats with this approach, namely that
* it is not very scalable to write JavaScript inline in this manner, and more pressing
* the Giraffe View Engine HTML-encodes the text provided to the `_onX` attributes.

Expand Down Expand Up @@ -3049,15 +3067,15 @@ function greet() {
Then, you could reference that javascript via a script element, and use `greet` in your event handler like so:

```fsharp
let page =
let page =
html [] [
head [] [
script [_type "application/javascript"
_src "/greet.js"] [] // include our `greet.js` function dynamically
]
body [] [
button [_id "greet-btn"
_onclick "greet()"] [] // use the `greet()` function from `greet.js` to say hello
_onclick "greet()"] [] // use the `greet()` function from `greet.js` to say hello
]
]
```
Expand Down
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Next create a web application and plug it into the ASP.NET Core middleware:
```fsharp
open System
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.DependencyInjection
open Giraffe
Expand All @@ -109,9 +109,12 @@ type Startup() =
[<EntryPoint>]
let main _ =
WebHostBuilder()
.UseKestrel()
.UseStartup<Startup>()
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(
fun webHostBuilder ->
webHostBuilder
.UseStartup<Startup>()
|> ignore)
.Build()
.Run()
0
Expand All @@ -122,7 +125,7 @@ Instead of creating a `Startup` class you can also add Giraffe in a more functio
```fsharp
open System
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.DependencyInjection
open Giraffe
Expand All @@ -141,10 +144,13 @@ let configureServices (services : IServiceCollection) =
[<EntryPoint>]
let main _ =
WebHostBuilder()
.UseKestrel()
.Configure(Action<IApplicationBuilder> configureApp)
.ConfigureServices(configureServices)
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(
fun webHostBuilder ->
webHostBuilder
.Configure(configureApp)
.ConfigureServices(configureServices)
|> ignore)
.Build()
.Run()
0
Expand Down
7 changes: 7 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Release Notes
=============

## 4.1.0

- Removed redundant dependencies
- Fixed model binding for arrays (see [#403](https://github.com/giraffe-fsharp/Giraffe/issues/403))
- Fixed pre-condition bug for the `If-Unmodified-Since` HTTP header (see [#402](https://github.com/giraffe-fsharp/Giraffe/issues/402))
- Added `netcoreapp3.1` support

## 4.0.1

Fixed dependency references for TFM `netcoreapp3.0` projects.
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ environment:
init:
- git config --global core.autocrlf true
install:
- ps: .\.psscripts\install-dotnet.ps1 -SdkVersions "3.0.100, 2.2.402"
- ps: .\.psscripts\install-dotnet.ps1 -SdkVersions "3.1.201, 3.0.100, 2.2.402"
build: off
build_script:
- ps: .\build.ps1 -Release -Pack
Expand All @@ -21,7 +21,7 @@ nuget:
deploy:
provider: NuGet
api_key:
secure: +XDgIu4Tmln7LKedNmQgMFnyKTxxuCKFRK3V5oKEfwZiakPXRd5C7OueEGBL50oh
secure: KmGt31DHQC3dKFI3ZLCDKd9S5CnH/cV2Rhx3D3J/5b3qSjBh2U+/HOKyOfxJqY2W
skip_symbols: false
artifact: /.*\.nupkg/
on:
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"projects": [ "src", "tests" ],
"sdk": {
"version": "3.0.100"
"version": "3.1.201"
}
}
2 changes: 1 addition & 1 deletion samples/GoogleAuthApp/GoogleAuthApp/GoogleAuthApp.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<DebugType>portable</DebugType>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
<RunWorkingDirectory>$(MSBuildThisFileDirectory)</RunWorkingDirectory>
Expand Down
16 changes: 10 additions & 6 deletions samples/GoogleAuthApp/GoogleAuthApp/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ open Microsoft.AspNetCore.Http
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.AspNetCore.Authentication
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.Logging
open Microsoft.Extensions.DependencyInjection
open FSharp.Control.Tasks.V2.ContextInsensitive
Expand Down Expand Up @@ -177,12 +178,15 @@ let main _ =
Scheme = Https
FilePath = Some "<path to self signed certificate>"
Password = Some "<password>" } ]

WebHostBuilder()
.UseKestrel(fun o -> o.ConfigureEndpoints endpoints)
.Configure(Action<IApplicationBuilder> configureApp)
.ConfigureServices(configureServices)
.ConfigureLogging(configureLogging)
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(
fun webHostBuilder ->
webHostBuilder
.UseKestrel(fun o -> o.ConfigureEndpoints endpoints)
.Configure(configureApp)
.ConfigureServices(configureServices)
.ConfigureLogging(configureLogging)
|> ignore)
.Build()
.Run()
0
2 changes: 1 addition & 1 deletion samples/IdentityApp/IdentityApp/IdentityApp.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<DebugType>portable</DebugType>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
<RunWorkingDirectory>$(MSBuildThisFileDirectory)</RunWorkingDirectory>
Expand Down
17 changes: 11 additions & 6 deletions samples/IdentityApp/IdentityApp/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Cors.Infrastructure
open Microsoft.AspNetCore.Hosting
open Microsoft.AspNetCore.Http
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.Logging
open Microsoft.Extensions.DependencyInjection
open Microsoft.AspNetCore.Identity
Expand Down Expand Up @@ -250,12 +251,16 @@ let configureLogging (builder : ILoggingBuilder) =

[<EntryPoint>]
let main _ =
WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.Configure(Action<IApplicationBuilder> configureApp)
.ConfigureServices(configureServices)
.ConfigureLogging(configureLogging)
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(
fun webHostBuilder ->
webHostBuilder
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.Configure(configureApp)
.ConfigureServices(configureServices)
.ConfigureLogging(configureLogging)
|> ignore)
.Build()
.Run()
0
5 changes: 2 additions & 3 deletions samples/JwtApp/JwtApp/JwtApp.fsproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<DebugType>portable</DebugType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
<RunWorkingDirectory>$(MSBuildThisFileDirectory)</RunWorkingDirectory>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.3" />
</ItemGroup>

<ItemGroup>
Expand Down
20 changes: 12 additions & 8 deletions samples/JwtApp/JwtApp/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.AspNetCore.Http
open Microsoft.Extensions.Logging
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.DependencyInjection
open Microsoft.IdentityModel.Tokens
open Giraffe
Expand Down Expand Up @@ -89,14 +90,17 @@ let configureLogging (builder : ILoggingBuilder) =
let main _ =
let contentRoot = Directory.GetCurrentDirectory()
let webRoot = Path.Combine(contentRoot, "WebRoot")
WebHostBuilder()
.UseKestrel()
.UseContentRoot(contentRoot)
.UseIISIntegration()
.UseWebRoot(webRoot)
.Configure(Action<IApplicationBuilder> configureApp)
.ConfigureServices(configureServices)
.ConfigureLogging(configureLogging)
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(
fun webHostBuilder ->
webHostBuilder
.UseKestrel()
.UseContentRoot(contentRoot)
.UseWebRoot(webRoot)
.Configure(configureApp)
.ConfigureServices(configureServices)
.ConfigureLogging(configureLogging)
|> ignore)
.Build()
.Run()
0
2 changes: 1 addition & 1 deletion samples/SampleApp/SampleApp.Tests/SampleApp.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>SampleApp.Tests</AssemblyName>
<DebugType>portable</DebugType>
</PropertyGroup>
Expand Down
Loading

0 comments on commit 612aa18

Please sign in to comment.