From 469e99eae5c46844dcbff5c2662e414abfd31c2e Mon Sep 17 00:00:00 2001 From: 64J0 Date: Fri, 29 Nov 2024 18:11:38 -0300 Subject: [PATCH] add file server to response caching sample --- samples/ResponseCachingApp/Program.fs | 13 ++++++++++++- samples/ResponseCachingApp/README.md | 2 ++ .../ResponseCachingApp/ResponseCachingApp.fsproj | 4 ++++ samples/ResponseCachingApp/assets/main.css | 15 +++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 samples/ResponseCachingApp/assets/main.css diff --git a/samples/ResponseCachingApp/Program.fs b/samples/ResponseCachingApp/Program.fs index 6ad7be66..352bffbf 100644 --- a/samples/ResponseCachingApp/Program.fs +++ b/samples/ResponseCachingApp/Program.fs @@ -3,11 +3,14 @@ open Microsoft.AspNetCore.Builder open Microsoft.AspNetCore.Http open Microsoft.Extensions.DependencyInjection open Microsoft.Extensions.Hosting +open Microsoft.Extensions.FileProviders open Giraffe open Giraffe.EndpointRouting +let STATIC_ASSETS_PATH = IO.Path.Combine(__SOURCE_DIRECTORY__, "assets") + let expensiveOperation () : DateTime = - let fiveSeconds = 5000 // ms + let fiveSeconds = 5_000 // ms Threading.Thread.Sleep fiveSeconds DateTime.Now @@ -48,9 +51,17 @@ let configureServices (services: IServiceCollection) = services.AddRouting().AddResponseCaching().AddGiraffe() |> ignore let configureApp (appBuilder: IApplicationBuilder) = + let fileServerOptions = + new FileServerOptions( + FileProvider = new PhysicalFileProvider(STATIC_ASSETS_PATH), + RequestPath = "/assets", + EnableDirectoryBrowsing = false + ) + appBuilder .UseRouting() .UseResponseCaching() + .UseFileServer(options = fileServerOptions) .UseEndpoints(fun e -> e.MapGiraffeEndpoints(endpoints)) .UseGiraffe(notFoundHandler) diff --git a/samples/ResponseCachingApp/README.md b/samples/ResponseCachingApp/README.md index a7c460fb..1114d09b 100644 --- a/samples/ResponseCachingApp/README.md +++ b/samples/ResponseCachingApp/README.md @@ -4,6 +4,8 @@ The purpose of this sample is to show how one can configure the Giraffe server t You can find their documentation here: [Giraffe Docs - Response Caching](https://giraffe.wiki/docs#response-caching). ++ Update november/2024: Adding a [file server](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files#usefileserver-for-default-documents) feature. You can use it checking the endpoint `http://localhost:5000/assets/main.css` after starting the web server. + ## How to test First, start the server at the terminal using: diff --git a/samples/ResponseCachingApp/ResponseCachingApp.fsproj b/samples/ResponseCachingApp/ResponseCachingApp.fsproj index ded0e2dd..9f62e21a 100644 --- a/samples/ResponseCachingApp/ResponseCachingApp.fsproj +++ b/samples/ResponseCachingApp/ResponseCachingApp.fsproj @@ -9,6 +9,10 @@ + + + + diff --git a/samples/ResponseCachingApp/assets/main.css b/samples/ResponseCachingApp/assets/main.css new file mode 100644 index 00000000..bd79827b --- /dev/null +++ b/samples/ResponseCachingApp/assets/main.css @@ -0,0 +1,15 @@ +.tippy-box[data-animation=shift-away-subtle][data-state=hidden] { + opacity: 0 +} + +.tippy-box[data-animation=shift-away-subtle][data-state=hidden][data-placement^=top] { + transform: translateY(5px) +} + +.tippy-box[data-animation=shift-away-subtle][data-state=hidden][data-placement^=bottom] { + transform: translateY(-5px) +} + +.tippy-box[data-animation=shift-away-subtle][data-state=hidden][data-placement^=left] { + transform: translate(5px) +} \ No newline at end of file