aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Startup.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-05-30 16:23:25 +0800
committercrupest <crupest@outlook.com>2020-05-30 16:23:25 +0800
commit232a19d7dfe0e3847b3a9a9a9be83485ffb9031c (patch)
tree2c7463f15cf30b8cbc703cb57bef357796bcd8b9 /Timeline/Startup.cs
parentfc0521d81aa2293b94ea40b79ec0df80966c0278 (diff)
downloadtimeline-232a19d7dfe0e3847b3a9a9a9be83485ffb9031c.tar.gz
timeline-232a19d7dfe0e3847b3a9a9a9be83485ffb9031c.tar.bz2
timeline-232a19d7dfe0e3847b3a9a9a9be83485ffb9031c.zip
Merge front end to this repo. But I need to wait for aspnet core support for custom port and package manager for dev server.
Diffstat (limited to 'Timeline/Startup.cs')
-rw-r--r--Timeline/Startup.cs45
1 files changed, 21 insertions, 24 deletions
diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs
index f5220446..8da09686 100644
--- a/Timeline/Startup.cs
+++ b/Timeline/Startup.cs
@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Mvc.Infrastructure;
+using Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@@ -16,6 +17,7 @@ using Timeline.Entities;
using Timeline.Formatters;
using Timeline.Helpers;
using Timeline.Models.Converters;
+using Timeline.Routes;
using Timeline.Services;
namespace Timeline
@@ -44,6 +46,7 @@ namespace Timeline
services.AddControllers(setup =>
{
setup.InputFormatters.Add(new StringInputFormatter());
+ setup.UseApiRoutePrefix("api");
})
.AddJsonOptions(options =>
{
@@ -61,29 +64,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 +93,11 @@ namespace Timeline
var pathProvider = services.GetRequiredService<IPathProvider>();
options.UseSqlite($"Data Source={pathProvider.GetDatabaseFilePath()}");
});
+
+ services.AddSpaStaticFiles(config =>
+ {
+ config.RootPath = "ClientApp/dist";
+ });
}
@@ -126,7 +111,7 @@ namespace Timeline
app.UseRouting();
- app.UseCors();
+ app.UseSpaStaticFiles();
app.UseAuthentication();
app.UseAuthorization();
@@ -135,6 +120,18 @@ namespace Timeline
{
endpoints.MapControllers();
});
+
+ app.UseSpa(spa =>
+ {
+ spa.Options.SourcePath = "ClientApp";
+
+ if (Environment.IsDevelopment())
+ {
+ // TODO! I'll waiting for aspnetcore to support custom package manager and port.
+ // It is already in master branch code but not published.
+ spa.UseReactDevelopmentServer(npmScript: "start");
+ }
+ });
}
}
}