-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartup.fs
More file actions
69 lines (56 loc) · 2.47 KB
/
Startup.fs
File metadata and controls
69 lines (56 loc) · 2.47 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
namespace UserAPI
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Configuration
open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.Hosting
open UserAPI.Services
type Startup private () =
member val Configuration: IConfiguration = null with get, set
member val _env: IWebHostEnvironment = null with get, set
new(configuration: IConfiguration, env: IWebHostEnvironment) as this =
Startup()
then
this.Configuration <- configuration
this._env <- env
// This method gets called by the runtime. Use this method to add services to the container.
member this.ConfigureServices(services: IServiceCollection) =
// Add swagger service
services.AddSwaggerGen(fun options -> options.IncludeXmlComments("Properties/UserAPI.xml"))
|> ignore
// Add Cors service
services.AddCors (fun options ->
options.AddPolicy(
"MyCorsPolicy",
fun builder ->
builder
.WithOrigins("http://localhost:5000")
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
|> ignore
))
|> ignore
// Add framework services.
services.AddControllers() |> ignore
services.AddHttpContextAccessor() |> ignore
services.AddMvcCore() |> ignore
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
member this.Configure(app: IApplicationBuilder, env: IWebHostEnvironment) =
if (env.IsDevelopment()) then
app.UseDeveloperExceptionPage() |> ignore
elif (env.IsProduction()) then
app.UseExceptionHandler() |> ignore
// Swagger for development
app.UseSwagger(fun options -> options.SerializeAsV2 <- true) |> ignore
app.UseSwaggerUI (fun options ->
options.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1")
options.RoutePrefix <- "")
|> ignore
app.UseRouting() |> ignore
app.UseAuthorization() |> ignore
app.UseCors("MyCorsPolicy") |> ignore
let baseUrl = this.Configuration.GetValue<string>("Develop:ApplicationUrl")
app.UseMiddleware<LoggerMiddleware>(baseUrl) |> ignore
app.UseEndpoints(fun endpoints -> endpoints.MapControllers() |> ignore)
|> ignore