-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.fs
More file actions
45 lines (38 loc) · 1.18 KB
/
Program.fs
File metadata and controls
45 lines (38 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module CS220.Program
open System
open Giraffe
open Microsoft.AspNetCore.Http
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.Logging
let js (path: string): HttpHandler =
fun (_next: HttpFunc) (ctx: HttpContext) ->
task {
ctx.SetContentType "text/javascript"
return! ctx.WriteFileStreamAsync (false, path, None, None)
}
let webApp =
choose [
route "/" >=> htmlFile "index.html"
routexp "/(.*)" (fun s -> js $"Mandelbrot/{Seq.item 1 s}")
]
let errorHandler (ex: Exception) (logger: ILogger) =
clearResponse
>=> setStatusCode 404 >=> text "Not found"
let configureApp (app: IApplicationBuilder) =
app.UseGiraffeErrorHandler(errorHandler)
.UseGiraffe(webApp)
let configureServices (services: IServiceCollection) =
services.AddGiraffe () |> ignore
[<EntryPoint>]
let main _args =
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(fun webHostbuilder ->
webHostbuilder.Configure(configureApp)
.ConfigureServices(configureServices)
|> ignore)
.Build()
.Run()
0