Skip to content

Instantly share code, notes, and snippets.

@zenatureza
Created August 28, 2020 17:03
Show Gist options
  • Save zenatureza/5dcfab1bb5e260f9b83704ceed266f96 to your computer and use it in GitHub Desktop.
Save zenatureza/5dcfab1bb5e260f9b83704ceed266f96 to your computer and use it in GitHub Desktop.
using ApplicationCore.Configuration;
using ApplicationCore.Domain.Entities.Log;
using ApplicationCore.Domain.Interfaces.Database.Repositories;
using Infrastructure.Configuration;
using Infrastructure.Database;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using RestApi.Filters;
namespace RestApi
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers(options =>
options.Filters.Add(new ApiExceptionFilter()));
services.AddApplicationCoreConfig();
services.AddInfrastructureConfig(Configuration);
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddCors(options =>
{
options.AddPolicy(name: MyAllowSpecificOrigins,
builder =>
{
builder
.WithOrigins(new string[] { "http://localhost:3000", "http://localhost:36813" })
.AllowAnyHeader()
.AllowAnyMethod();
});
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseCors(MyAllowSpecificOrigins);
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.UseAuthentication();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment