aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Startup.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Timeline/Startup.cs')
-rw-r--r--Timeline/Startup.cs42
1 files changed, 18 insertions, 24 deletions
diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs
index f5220446..b6c3ff7f 100644
--- a/Timeline/Startup.cs
+++ b/Timeline/Startup.cs
@@ -16,6 +16,7 @@ using Timeline.Entities;
using Timeline.Formatters;
using Timeline.Helpers;
using Timeline.Models.Converters;
+using Timeline.Routes;
using Timeline.Services;
namespace Timeline
@@ -44,6 +45,7 @@ namespace Timeline
services.AddControllers(setup =>
{
setup.InputFormatters.Add(new StringInputFormatter());
+ setup.UseApiRoutePrefix("api");
})
.AddJsonOptions(options =>
{
@@ -61,29 +63,6 @@ namespace Timeline
.AddScheme<MyAuthenticationOptions, MyAuthenticationHandler>(AuthenticationConstants.Scheme, AuthenticationConstants.DisplayName, o => { });
services.AddAuthorization();
-
- if (Environment.IsDevelopment())
- {
- services.AddCors(setup =>
- {
- setup.AddDefaultPolicy(builder =>
- {
- builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin();
- });
- });
- }
- else
- {
- var corsConfig = Configuration.GetSection("Cors").Get<string[]>();
- services.AddCors(setup =>
- {
- setup.AddDefaultPolicy(builder =>
- {
- builder.AllowAnyHeader().AllowAnyMethod().WithOrigins(corsConfig);
- });
- });
- }
-
services.AddScoped<IPathProvider, PathProvider>();
services.AddAutoMapper(GetType().Assembly);
@@ -113,6 +92,11 @@ namespace Timeline
var pathProvider = services.GetRequiredService<IPathProvider>();
options.UseSqlite($"Data Source={pathProvider.GetDatabaseFilePath()}");
});
+
+ services.AddSpaStaticFiles(config =>
+ {
+ config.RootPath = "ClientApp/dist";
+ });
}
@@ -126,7 +110,7 @@ namespace Timeline
app.UseRouting();
- app.UseCors();
+ app.UseSpaStaticFiles();
app.UseAuthentication();
app.UseAuthorization();
@@ -135,6 +119,16 @@ namespace Timeline
{
endpoints.MapControllers();
});
+
+ app.UseSpa(spa =>
+ {
+ spa.Options.SourcePath = "ClientApp";
+
+ if (Environment.IsDevelopment())
+ {
+ SpaServices.SpaDevelopmentServerMiddlewareExtensions.UseSpaDevelopmentServer(spa, packageManager: "yarn", npmScript: "start", port: 3000);
+ }
+ });
}
}
}