DocSpace-client/web/ASC.Web.Studio/Startup.cs

100 lines
2.9 KiB
C#
Raw Normal View History

2019-06-06 08:44:38 +00:00
using ASC.Common.DependencyInjection;
2019-06-04 14:43:20 +00:00
using ASC.Common.Logging;
2019-06-06 08:44:38 +00:00
using ASC.Common.Utils;
2019-06-04 14:43:20 +00:00
using ASC.Data.Storage;
2019-06-10 12:54:10 +00:00
using ASC.Data.Storage.Configuration;
2019-05-15 14:56:09 +00:00
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace ASC.Web.Studio
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddCors();
2019-06-04 14:43:20 +00:00
2019-06-06 13:34:46 +00:00
services.AddMvc();
services.AddMemoryCache();
2019-06-07 08:59:07 +00:00
services.AddDistributedMemoryCache();
services.AddSession();
2019-06-06 13:34:46 +00:00
2019-05-15 14:56:09 +00:00
/*services.AddMvc(options => options.EnableEndpointRouting = false)
.AddNewtonsoftJson();*/
// In production, the React files will be served from this directory
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/build";
2019-06-04 14:43:20 +00:00
});
2019-06-10 16:15:34 +00:00
services.AddAutofac(Configuration);
2019-06-06 08:44:38 +00:00
services.AddHttpContextAccessor()
2019-06-10 12:54:10 +00:00
.AddStorage()
2019-06-10 16:15:34 +00:00
.AddLogManager();
2019-05-15 14:56:09 +00:00
}
// 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();
}
else
{
app.UseExceptionHandler("/Error");
}
2019-06-04 14:43:20 +00:00
app.UseRouting();
2019-05-15 14:56:09 +00:00
2019-05-30 07:33:38 +00:00
app.UseCors(builder =>
builder
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod());
2019-05-15 14:56:09 +00:00
app.UseStaticFiles();
2019-06-04 14:43:20 +00:00
app.UseSpaStaticFiles();
2019-06-07 08:59:07 +00:00
app.UseSession();
2019-05-15 14:56:09 +00:00
/*app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action=Index}/{id?}");
2019-06-04 14:43:20 +00:00
});*/
2019-06-24 08:20:03 +00:00
app.UseCSP();
app.UseCm();
2019-06-06 08:44:38 +00:00
2019-06-04 14:43:20 +00:00
app.UseEndpoints(endpoints =>
{
endpoints.InitializeHttpHandlers();
});
2019-05-15 14:56:09 +00:00
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
});
}
}
}