aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Startup.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-05-30 23:41:31 +0800
committerGitHub <noreply@github.com>2020-05-30 23:41:31 +0800
commitc8d71a3b5e7aef4fcf75bad44b7be90b45aaaf0b (patch)
treef76ecd77c99c4136d1ab4771b91a92f1e5ad4a35 /Timeline/Startup.cs
parent7e393559d2883a37b1be0c82cccc06bc97c3d102 (diff)
parent83de798e74323e96e81b8196b04e23ed2bd4efbf (diff)
downloadtimeline-c8d71a3b5e7aef4fcf75bad44b7be90b45aaaf0b.tar.gz
timeline-c8d71a3b5e7aef4fcf75bad44b7be90b45aaaf0b.tar.bz2
timeline-c8d71a3b5e7aef4fcf75bad44b7be90b45aaaf0b.zip
Merge pull request #72 from crupest/merge-frontend
Merge frontend repo into this repo.
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);
+ }
+ });
}
}
}