source: resTools_backend/backend/Program.cs@ cc4db18

Last change on this file since cc4db18 was cc4db18, checked in by Danilo <danilo.najkov@…>, 2 years ago

reservation module changes + contact module + menu module

  • Property mode set to 100644
File size: 2.3 KB
Line 
1using backend.Data;
2using backend.Helpers;
3using backend.Services;
4using Microsoft.EntityFrameworkCore;
5using Microsoft.OpenApi.Models;
6using WebApi.Helpers;
7
8var builder = WebApplication.CreateBuilder(args);
9
10// Add services to the container.
11builder.Services.Configure<AppSettings>(builder.Configuration.GetSection("AppSettings"));
12builder.Services.AddControllers().AddNewtonsoftJson();
13// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
14builder.Services.AddEndpointsApiExplorer();
15builder.Services.AddSwaggerGen(c =>
16{
17 c.SwaggerDoc("v1", new OpenApiInfo() { Title = "resTools backend", Version = "v1" });
18 c.AddSecurityDefinition("Bearer",
19 new OpenApiSecurityScheme
20 {
21 In = Microsoft.OpenApi.Models.ParameterLocation.Header,
22 Description = "Please enter into field the word 'Bearer' following by space and JWT",
23 Name = "Authorization",
24 Type = Microsoft.OpenApi.Models.SecuritySchemeType.ApiKey,
25 Scheme="Bearer"
26 });
27 c.AddSecurityRequirement(new OpenApiSecurityRequirement()
28 {
29 {
30 new OpenApiSecurityScheme
31 {
32 Reference = new OpenApiReference
33 {
34 Type = ReferenceType.SecurityScheme,
35 Id = "Bearer"
36 },
37 Name = "Bearer",
38 In = ParameterLocation.Header,
39
40 },
41 new List<string>()
42 }
43 });
44});
45builder.Services.AddScoped<IUserService, UserService>();
46builder.Services.AddScoped<IRestaurantService, RestaurantService>();
47builder.Services.AddScoped<IReservationService, ReservationService>();
48builder.Services.AddScoped<IMenuService, MenuService>();
49builder.Services.AddScoped<ISmsService, SmsService>();
50
51builder.Services.AddDbContext<DataContext>(p => p.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
52
53var app = builder.Build();
54
55app.UseCors(x => x
56 .AllowAnyOrigin()
57 .AllowAnyMethod()
58 .AllowAnyHeader());
59
60// custom jwt auth middleware
61app.UseMiddleware<JwtMiddleware>();
62
63// Configure the HTTP request pipeline.
64if (app.Environment.IsDevelopment())
65{
66 app.UseSwagger();
67 app.UseSwaggerUI();
68}
69
70app.UseHttpsRedirection();
71
72app.UseAuthorization();
73
74app.MapControllers();
75
76app.Run();
Note: See TracBrowser for help on using the repository browser.