-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathProgram.fs
84 lines (71 loc) · 2.42 KB
/
Program.fs
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
module Fsharplangru.App
open System
open System.IO
open System.Collections.Generic
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.AspNetCore.Http
open Microsoft.Extensions.Logging
open Microsoft.Extensions.DependencyInjection
open Giraffe.HttpHandlers
open Giraffe.Middleware
open Giraffe.XmlViewEngine
open Fsharplangru.Views
// ---------------------------------
// Web app
// ---------------------------------
let indexPage =
[
Navigation.section
Jumbotron.sectionImage
Jumbotron.sectionWithLogo
SourceCodeExamples.section
WhyFsharp.section
TryOnline.section
Videos.section
Footer.section
Scripts.code
]
|> Layout.page "F#: Русскоязычное сообщество"
let webApp =
choose [
GET >=>
choose [
route "/" >=> renderHtml indexPage
// routef "/%s" ( Layout.page >> renderHtml )
// route "/" >=> razorHtmlView "Index" { Text = "Hello world, from Giraffe!" }
]
setStatusCode 404 >=> text "Not Found" ]
// ---------------------------------
// Error handler
// ---------------------------------
let errorHandler (ex : Exception) (logger : ILogger) =
logger.LogError(EventId(), ex, "An unhandled exception has occurred while executing the request.")
clearResponse >=> setStatusCode 500 >=> text ex.Message
// ---------------------------------
// Config and Main
// ---------------------------------
let configureApp (app : IApplicationBuilder) =
app.UseGiraffeErrorHandler errorHandler
app.UseStaticFiles() |> ignore
app.UseGiraffe webApp
let configureServices (services : IServiceCollection) =
()
let configureLogging (builder : ILoggingBuilder) =
let filter (l : LogLevel) = l.Equals LogLevel.Error
builder.AddFilter(filter).AddConsole().AddDebug() |> ignore
[<EntryPoint>]
let main argv =
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)
.Build()
.Run()
0