Guest User

Untitled

a guest
Oct 17th, 2019
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Builder;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Microsoft.AspNetCore.HttpsPolicy;
  8. using Microsoft.AspNetCore.Mvc;
  9. using Microsoft.Extensions.Configuration;
  10. using Microsoft.Extensions.DependencyInjection;
  11. using Microsoft.Extensions.Hosting;
  12. using Microsoft.Extensions.Logging;
  13. using Microsoft.EntityFrameworkCore;
  14. using BottleBitAPI.Repositories;
  15.  
  16. namespace BottleBitAPI
  17. {
  18.     public class Startup
  19.     {
  20.         public Startup(IConfiguration configuration)
  21.         {
  22.             Configuration = configuration;
  23.         }
  24.  
  25.         public IConfiguration Configuration { get; }
  26.  
  27.         // This method gets called by the runtime. Use this method to add services to the container.
  28.         public void ConfigureServices(IServiceCollection services)
  29.         {  
  30.  
  31.             services.AddCors(options =>
  32.         {
  33.             options.AddPolicy("CorsPolicy",
  34.                 builder => builder.AllowAnyOrigin()
  35.                 .AllowAnyMethod()
  36.                 .AllowAnyHeader());
  37.         });
  38.             /*
  39.                 Gets the connection string from "DefaultConnection" in
  40.                 appsettings.json from the source folder
  41.             */
  42.             services.AddDbContext<CommandContext>(options =>
  43.                options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));
  44.             services.AddControllers();
  45.         }
  46.  
  47.         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  48.         public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  49.         {
  50.             if (env.IsDevelopment())
  51.             {
  52.                 app.UseDeveloperExceptionPage();
  53.             }
  54.  
  55.             app.UseHttpsRedirection();
  56.  
  57.             app.UseRouting();
  58.  
  59.             app.UseCors("CorsPolicy");
  60.  
  61.             app.UseAuthorization();
  62.  
  63.             app.UseEndpoints(endpoints =>
  64.             {
  65.                 endpoints.MapControllers();
  66.             });
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment